Skip to content

Commit 15073a5

Browse files
fix: copy API serverless function into output directory for Vercel detection
Vercel's `framework: null` defaults outputDirectory to `public/` when that directory exists and only detects serverless functions INSIDE the output directory. The bundled `api/index.js` was at the project root (outside `public/`) so Vercel never recognised it — all `/api/*` routes fell through to the SPA catch-all and returned `index.html`. Added step 4 to `build-vercel.sh` that copies `api/index.js` into `public/api/` after the SPA files are placed in `public/`. This ensures Vercel detects it as a serverless function within the output directory. Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/85727540-2aac-406e-83f5-790a0c650da3 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 76e66ad commit 15073a5

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- **Studio Vercel API routes returning HTML instead of JSON** — Updated
12-
`apps/studio/vercel.json` to correctly configure Vercel serverless functions.
13-
Added `outputDirectory: "public"` so Vercel serves static files from the
14-
correct directory and the `api/` directory is auto-detected for serverless
15-
functions. Removed the `functions` block (the in-code `export const config`
16-
in `server/index.ts` already configures memory/maxDuration without pre-build
12+
`apps/studio/scripts/build-vercel.sh` to copy the bundled serverless function
13+
(`api/index.js`) into the output directory (`public/api/`). Vercel's
14+
`framework: null` defaults `outputDirectory` to `public/` when that directory
15+
exists, and only detects serverless functions **inside** the output directory.
16+
Previously `api/index.js` was generated at the project root (outside `public/`)
17+
and Vercel never recognised it, causing all `/api/*` routes to fall through to
18+
the SPA catch-all rewrite. Also set `outputDirectory: "public"` explicitly in
19+
`vercel.json` for clarity, and removed the `functions` block (the in-code
20+
`export const config` already configures memory/maxDuration without pre-build
1721
file-pattern validation errors).
1822
- **Studio CORS error on Vercel temporary/preview domains** — Changed
1923
`VITE_SERVER_URL` from hardcoded `https://play.objectstack.ai` to `""`

apps/studio/scripts/build-vercel.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ set -euo pipefail
33

44
# Build script for Vercel deployment of @objectstack/studio.
55
#
6-
# Without outputDirectory, Vercel serves static files from public/.
7-
# Serverless functions are detected from api/ at the project root.
6+
# Vercel uses outputDirectory (vercel.json → "public") for BOTH static files
7+
# and serverless function detection. The api/ subdirectory MUST be inside
8+
# the output directory — files at the project root are ignored.
89
#
910
# Steps:
1011
# 1. Turbo build (Vite SPA → dist/)
1112
# 2. Bundle the API serverless function (→ api/index.js)
1213
# 3. Copy Vite output to public/ for Vercel CDN serving
14+
# 4. Copy API function into public/api/ so Vercel detects it
1315

1416
echo "[build-vercel] Starting studio build..."
1517

@@ -26,4 +28,11 @@ rm -rf public
2628
mkdir -p public
2729
cp -r dist/* public/
2830

29-
echo "[build-vercel] Done. Static files in public/, serverless function in api/index.js"
31+
# 4. Copy API function into output directory for Vercel detection
32+
# Vercel only looks for serverless functions inside outputDirectory.
33+
# Without this step, api/index.js at the project root is invisible.
34+
mkdir -p public/api
35+
cp api/index.js public/api/
36+
cp api/index.js.map public/api/ 2>/dev/null || true
37+
38+
echo "[build-vercel] Done. Static files + API function in public/"

0 commit comments

Comments
 (0)