Skip to content

Commit 9f8bb6f

Browse files
authored
Merge pull request #1004 from objectstack-ai/copilot/fix-output-directory-mismatch
2 parents 2a392b9 + b4ab44b commit 9f8bb6f

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
@@ -54,6 +54,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5454
to `:memory:` (ephemeral SQLite). This ensures data persistence across serverless function
5555
invocations on Vercel. The browser MSW mock kernel remains unchanged (InMemoryDriver).
5656

57+
### Fixed
58+
- **Vercel API always returns HTML — serverless function entrypoint not found** — The `bundle-api.mjs`
59+
script was emitting `api/index.js` at the project root, but `vercel.json` sets `outputDirectory: "dist"`,
60+
so Vercel could not discover the serverless function and fell back to the SPA HTML route for all
61+
`/api/*` requests. Changed esbuild `outfile` to `dist/api/index.js` and added explicit `functions`
62+
config in `vercel.json` with `@vercel/node@3` runtime.
63+
5764
### Added
5865
- **Batch schema sync for remote DDL in kernel bootstrap**`ObjectQLPlugin.syncRegisteredSchemas()`
5966
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)