diff --git a/examples/app-host/.npmrc b/examples/app-host/.npmrc deleted file mode 100644 index 4a3d47b9a..000000000 --- a/examples/app-host/.npmrc +++ /dev/null @@ -1,3 +0,0 @@ -# Vercel pnpm configuration -# Use hoisted node_modules structure instead of symlinks to avoid Vercel packaging errors. -node-linker=hoisted diff --git a/examples/app-host/scripts/build-vercel.sh b/examples/app-host/scripts/build-vercel.sh index aba537113..3b70d99d9 100755 --- a/examples/app-host/scripts/build-vercel.sh +++ b/examples/app-host/scripts/build-vercel.sh @@ -7,20 +7,33 @@ set -euo pipefail # - api/[[...route]].js is committed to the repo (Vercel detects it pre-build) # - esbuild bundles server/index.ts → api/_handler.js (self-contained bundle) # - The committed .js wrapper re-exports from _handler.js at runtime +# - Studio SPA is built and copied to public/ for serving the UI # # Steps: -# 1. Build the project with turbo +# 1. Build the project with turbo (includes studio) # 2. Bundle the API serverless function (→ api/_handler.js) -# 3. Copy native/external modules into local node_modules for Vercel packaging +# 3. Copy studio dist files to public/ for UI serving echo "[build-vercel] Starting app-host build..." # 1. Build the project with turbo (from monorepo root) +# This builds both app-host and studio cd ../.. -pnpm turbo run build --filter=@example/app-host +pnpm turbo run build --filter=@example/app-host --filter=@objectstack/studio cd examples/app-host # 2. Bundle API serverless function node scripts/bundle-api.mjs -echo "[build-vercel] Done. Serverless function in api/[[...route]].js → api/_handler.js" +# 3. Copy studio dist files to public/ for UI serving +echo "[build-vercel] Copying studio dist to public/..." +rm -rf public +mkdir -p public +if [ -d "../../apps/studio/dist" ]; then + cp -r ../../apps/studio/dist/* public/ + echo "[build-vercel] ✓ Copied studio dist to public/" +else + echo "[build-vercel] ⚠ Studio dist not found (skipped)" +fi + +echo "[build-vercel] Done. Static files in public/, serverless function in api/[[...route]].js → api/_handler.js" diff --git a/examples/app-host/vercel.json b/examples/app-host/vercel.json index 7c2d6eca0..b5d49f112 100644 --- a/examples/app-host/vercel.json +++ b/examples/app-host/vercel.json @@ -9,7 +9,16 @@ "maxDuration": 60 } }, + "headers": [ + { + "source": "/assets/(.*)", + "headers": [ + { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" } + ] + } + ], "rewrites": [ - { "source": "/api/:path*", "destination": "/api/[[...route]]" } + { "source": "/api/:path*", "destination": "/api/[[...route]]" }, + { "source": "/((?!api/).*)", "destination": "/index.html" } ] }