Skip to content

Commit b4ab44b

Browse files
Copilothotlong
andauthored
fix: output serverless function to dist/api/index.js to match Vercel outputDirectory
The bundle-api.mjs script was emitting api/index.js at the project root, but vercel.json sets outputDirectory: "dist" — so Vercel could not discover the serverless function and fell back to the SPA HTML route for all /api/* requests. - Change esbuild outfile from api/index.js to dist/api/index.js - Add explicit functions config in vercel.json with @vercel/node@3 runtime - Remove obsolete .gitignore entries for api/index.js (now under dist/) - Update changeset and CHANGELOG Fixes #1002 Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/24bf6f10-3ca1-4cff-a9cb-c6c0905d1845 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 61955f7 commit b4ab44b

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

.changeset/fix-vercel-api-html-response.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
Fix Vercel deployment API endpoints returning HTML instead of JSON.
66

7-
Replace the custom `getRequestListener` export in `server/index.ts` with the
8-
standard `handle()` adapter from `@hono/node-server/vercel` and the
9-
outer→inner Hono delegation pattern (`inner.fetch(c.req.raw)`).
7+
The `bundle-api.mjs` script was emitting the serverless function to `api/index.js`
8+
at the project root, but `vercel.json` sets `outputDirectory: "dist"` — causing
9+
Vercel to never find the function entrypoint and fall back to the SPA HTML route
10+
for all `/api/*` requests.
1011

11-
- The `handle()` adapter correctly wraps the Hono app with the
12-
`(IncomingMessage, ServerResponse) => Promise<void>` signature that
13-
Vercel's Node.js runtime expects for serverless functions in `api/`.
14-
- `@hono/node-server/vercel`'s `getRequestListener()` already handles
15-
Vercel's pre-buffered `rawBody` natively, removing the need for the
16-
custom body-extraction helper.
17-
- The outer→inner delegation pattern matches the documented ObjectStack
18-
Vercel deployment guide and the `@objectstack/hono` adapter test suite.
12+
- Change esbuild `outfile` from `api/index.js` to `dist/api/index.js` so the
13+
bundled serverless function lands inside the Vercel output directory.
14+
- Add explicit `functions` config in `vercel.json` pointing to `api/index.js`
15+
(relative to `outputDirectory`) with `@vercel/node@3` runtime.
16+
- Remove obsolete `.gitignore` entries for `api/index.js` and `api/index.js.map`
17+
(now emitted under `dist/` which is already git-ignored).

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
to `:memory:` (ephemeral SQLite). This ensures data persistence across serverless function
4040
invocations on Vercel. The browser MSW mock kernel remains unchanged (InMemoryDriver).
4141

42+
### Fixed
43+
- **Vercel API always returns HTML — serverless function entrypoint not found** — The `bundle-api.mjs`
44+
script was emitting `api/index.js` at the project root, but `vercel.json` sets `outputDirectory: "dist"`,
45+
so Vercel could not discover the serverless function and fell back to the SPA HTML route for all
46+
`/api/*` requests. Changed esbuild `outfile` to `dist/api/index.js` and added explicit `functions`
47+
config in `vercel.json` with `@vercel/node@3` runtime.
48+
4249
### Added
4350
- **Batch schema sync for remote DDL in kernel bootstrap**`ObjectQLPlugin.syncRegisteredSchemas()`
4451
now groups objects by driver and uses `syncSchemasBatch()` when the driver advertises

apps/studio/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ pnpm-lock.yaml
66
dist
77
build
88
*.tsbuildinfo
9-
api/index.js
10-
api/index.js.map
119

1210
# Development
1311
.vite

apps/studio/scripts/bundle-api.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ await build({
3737
platform: 'node',
3838
format: 'esm',
3939
target: 'es2020',
40-
outfile: 'api/index.js',
40+
outfile: 'dist/api/index.js',
4141
sourcemap: true,
4242
external: EXTERNAL,
4343
// Silence warnings about optional/unused require() calls in knex drivers
4444
logOverride: { 'require-resolve-not-external': 'silent' },
4545
});
4646

47-
console.log('[bundle-api] Bundled server/index.ts → api/index.js');
47+
console.log('[bundle-api] Bundled server/index.ts → dist/api/index.js');

apps/studio/vercel.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"installCommand": "cd ../.. && pnpm install",
55
"buildCommand": "cd ../.. && pnpm turbo run build --filter=@objectstack/studio && cd apps/studio && node scripts/bundle-api.mjs",
66
"outputDirectory": "dist",
7+
"functions": {
8+
"api/index.js": {
9+
"runtime": "@vercel/node@3"
10+
}
11+
},
712
"build": {
813
"env": {
914
"VITE_RUNTIME_MODE": "server",

0 commit comments

Comments
 (0)