Add Vercel deployment guide for MSW and Server modes#658
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new deployment guide describing how to deploy ObjectStack apps to Vercel in two modes—MSW (static SPA) and Server (serverless/edge)—and wires it into the Guides navigation.
Changes:
- Added a new “Deploy to Vercel” guide covering MSW mode and server-mode options (Next.js + Edge/Hono).
- Registered the new guide in the Guides sidebar metadata (Operations section).
- Linked the guide from the Guides index Operations table.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
content/docs/guides/deployment-vercel.mdx |
New Vercel deployment guide with MSW + server/edge patterns, env vars, and checklists |
content/docs/guides/meta.json |
Adds deployment-vercel under the Operations section |
content/docs/guides/index.mdx |
Adds “Deploy to Vercel” link to the Operations table |
| result = await dispatcher.handleData(subPath, method, body, queryParams, {}); | ||
| break; | ||
| case 'meta': | ||
| result = await dispatcher.handleMetadata(subPath, {}, method, body); |
There was a problem hiding this comment.
HttpDispatcher.handleData/handleMetadata expect a context with at least { request: ... } (used for broker call options, auth, etc.), but this example passes {}. That can break features that rely on request context (sessions, headers, IP, tracing). Pass the underlying request (or a minimal context object) through to the dispatcher methods.
| result = await dispatcher.handleData(subPath, method, body, queryParams, {}); | |
| break; | |
| case 'meta': | |
| result = await dispatcher.handleMetadata(subPath, {}, method, body); | |
| result = await dispatcher.handleData(subPath, method, body, queryParams, { request: c.req }); | |
| break; | |
| case 'meta': | |
| result = await dispatcher.handleMetadata(subPath, { request: c.req }, method, body); |
| // Dispatch based on first segment (data, meta, auth, etc.) | ||
| const body = ['POST', 'PATCH', 'PUT'].includes(method) | ||
| ? await c.req.json().catch(() => ({})) | ||
| : {}; | ||
|
|
||
| const subPath = segments.slice(1).join('/'); | ||
| let result; | ||
|
|
||
| switch (segments[0]) { | ||
| case 'data': | ||
| const queryParams: Record<string, any> = {}; | ||
| url.searchParams.forEach((v, k) => (queryParams[k] = v)); | ||
| result = await dispatcher.handleData(subPath, method, body, queryParams, {}); | ||
| break; | ||
| case 'meta': | ||
| result = await dispatcher.handleMetadata(subPath, {}, method, body); | ||
| break; | ||
| default: | ||
| return c.json({ error: 'Not Found' }, 404); | ||
| } |
There was a problem hiding this comment.
The comment says the catch-all dispatches based on the first segment “(data, meta, auth, etc.)”, but the switch only implements data and meta. Either expand the example to handle the other protocol segments (auth/graphql/storage/...) or adjust the wording so it matches what the code actually does.
|
|
||
| export const GET = handle(app); | ||
| export const POST = handle(app); | ||
| export const PATCH = handle(app); |
There was a problem hiding this comment.
This Edge Function example prepares to accept PUT requests (it parses JSON for PUT), but the exported handlers omit PUT, so Vercel will not route PUT requests to the app. Export PUT (and any other required methods) alongside GET/POST/PATCH/DELETE.
| export const PATCH = handle(app); | |
| export const PATCH = handle(app); | |
| export const PUT = handle(app); |
| return routeHandler(...args); | ||
| } | ||
|
|
||
| export { handler as GET, handler as POST, handler as PATCH, handler as DELETE }; |
There was a problem hiding this comment.
Next.js App Router needs explicit exports for each HTTP method. createRouteHandler supports PUT (used for metadata writes), but this example only exports GET/POST/PATCH/DELETE, so PUT requests will return 405. Export PUT as well (and any other methods you intend to support).
| export { handler as GET, handler as POST, handler as PATCH, handler as DELETE }; | |
| export { handler as GET, handler as POST, handler as PUT, handler as PATCH, handler as DELETE }; |
| ### Option B: Hono on Vercel Edge | ||
|
|
||
| Use the `@objectstack/hono` adapter for lightweight Edge Function deployments: | ||
|
|
||
| ```typescript | ||
| // api/[...route].ts (Vercel Edge Function) | ||
| import { Hono } from 'hono'; | ||
| import { handle } from 'hono/vercel'; | ||
| import { ObjectKernel, DriverPlugin, AppPlugin, HttpDispatcher } from '@objectstack/runtime'; |
There was a problem hiding this comment.
This section says to use the @objectstack/hono adapter, but the package currently only exposes objectStackMiddleware() and does not provide a route handler/dispatcher integration. The example also doesn’t import anything from @objectstack/hono, so readers can’t actually follow the instruction as written. Either update the text to describe the manual HttpDispatcher approach, or update the example to use the adapter API (once it exists).
| // Catch-all route — delegates to HttpDispatcher | ||
| app.all('/*', async (c) => { | ||
| const k = await getKernel(); | ||
| const dispatcher = new HttpDispatcher(k); | ||
| const method = c.req.method; |
There was a problem hiding this comment.
The Hono Edge example instantiates HttpDispatcher, but HttpDispatcher is marked @deprecated in @objectstack/runtime with guidance to use createDispatcherPlugin() instead and a note that it will be removed in v2. Publishing a deployment guide that depends on a deprecated API is likely to age poorly; consider switching the guide to the recommended non-deprecated approach, or explicitly label this option as legacy/temporary with a migration note.
Documents how to deploy ObjectStack applications to Vercel in two modes: MSW (static SPA with in-browser kernel) and Server (Serverless Functions with real database).
Changes
content/docs/guides/deployment-vercel.mdx— New guide covering:vercel.jsonwith SPA rewrites, monorepo config@objectstack/nextjscatch-all route handler with kernel singleton patternHttpDispatcher-based routing on Vercel Edge Functions?mode=msw|server), deployment checklists, feature comparison tablecontent/docs/guides/meta.json— Addeddeployment-vercelto Operations sectioncontent/docs/guides/index.mdx— Added guide to Operations tableKey patterns documented
MSW mode (
vercel.json):{ "framework": "vite", "build": { "env": { "VITE_RUNTIME_MODE": "msw" } }, "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }Server mode (Next.js catch-all):
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.