Uh oh!
There was an error while loading. Please reload this page.
fix(studio): replace custom getRequestListener with handle() from @hono/node-server/vercel - #1001
Merged
Merged
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…rverless export Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/825b1adb-d7ef-4152-97db-b5f2585ac9d6 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
CopilotAI
changed the title
[WIP] Fix API endpoints returning HTML instead of JSONfix(studio): replace custom getRequestListener with handle() from @hono/node-server/vercelMar 31, 2026
hotlong
marked this pull request as ready for review
March 31, 2026 03:17
Uh oh!
There was an error while loading. Please reload this page.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Vercel deployments where /api/v1/* routes were falling through to the SPA rewrite and returning index.html instead of JSON, by switching the serverless entrypoint export to Hono’s official Vercel adapter.
Changes:
- Replace the custom
getRequestListener-based export withhandle()from@hono/node-server/vercel. - Introduce an outer Hono app that delegates all requests to the lazily-booted inner ObjectStack Hono app via
inner.fetch(c.req.raw). - Add a patch changeset for
@objectstack/studiodocumenting the Vercel fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/studio/server/index.ts | Switches to the official Hono Vercel adapter (handle) and uses an outer→inner delegation wrapper to ensure Vercel recognizes the function handler. |
| .changeset/fix-vercel-api-html-response.md | Adds a patch changeset describing the production fix and why the adapter change resolves the HTML response issue. |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/api/v1/packagesand/api/v1/metareturn the SPA'sindex.htmlinstead of JSON on Vercel because the serverless function export was using a hand-rolledgetRequestListener()callback — diverging from the official Vercel adapter pattern and causing Vercel's function resolver to fail silently, falling through to the SPA rewrite.Changes
apps/studio/server/index.tsgetRequestListener(manual) →handle()from@hono/node-server/vercel(official adapter)Honoapp using the documented outer→inner delegation pattern;handle(app)becomes the default exportextractBodyhelper —@hono/node-server/vercelalready handles Vercel's pre-bufferedrawBodynatively.changeset/fix-vercel-api-html-response.md— patch changeset for@objectstack/studioOriginal prompt
Problem
After deploying to Vercel, the API endpoints incorrectly return HTML (the SPA's
index.html) instead of JSON responses:Root Cause Analysis
The deployment architecture has a critical mismatch between where the serverless function is built and where Vercel expects to find it:
vercel.jsonsets"outputDirectory": "dist"(Vite build output for the SPA)bundle-api.mjsbundlesserver/index.ts→api/index.js(in theapps/studio/root, NOT indist/){ "source": "/api/(.*)", "destination": "/api" }expects a serverless function atapi/index.js, but Vercel looks for functions relative to the project root OR the output directory{ "source": "/((?!api/).*)", "destination": "/index.html" }, which returns HTMLAdditionally, the current
server/index.tsexports viagetRequestListener()from@hono/node-server, which returns a(IncomingMessage, ServerResponse) => voidNode listener. While this can work, Vercel's Node.js runtime has better compatibility with the@hono/verceladapter'shandle()function which properly wraps the app for Vercel's expected function signature.Required Fix (Sustainable, Production-Grade)
1. Fix
apps/studio/scripts/bundle-api.mjsThe bundled output
api/index.jsmust be placed where Vercel can find it as a serverless function. SinceoutputDirectoryisdist, and Vercel discovers functions from the project directory (not the output directory), the currentapi/index.jspath should work IF the function is correctly exported.2. Fix
apps/studio/server/index.tsexportReplace
getRequestListener()with the standard Vercel adapter pattern usinghandle()from@hono/vercel:Or alternatively, keep the current approach but ensure the export is compatible:
3. Fix
apps/studio/vercel.jsonrewritesThe rewrites must correctly handle the ordering. The current
/api/(.*)→/apirewrite should work, but ensure the SPA fallback doesn't accidentally catch API routes. Consider usingheadersto ensure API responses have the correctContent-Type.4. Ensure
api/index.jsis available to VercelThe
bundle-api.mjsscript runs as part of the build command. Verify that Vercel can access the output atapi/index.jsafter the build completes. The.gitignorealready ignoresapi/index.jsandapi/index.js.map, confirming they are build artifacts.Key Files to Examine and Modify
apps/studio/vercel.json— Rewrites and function configurationapps/studio/server/index.ts— Serverless function entrypointapps/studio/scripts/bundle-api.mjs— Build script that bundles the API functionapps/studio/package.json— Dependencies (ensure@hono/node-serverorhono/vercelis available)Verification
After the fix:
pnpm turbo run test --filter=@objectstack/studiopnpm turbo run test --filter=@objectstack/honoGET /api/v1/metareturns{ "success": true, ... }JSONGET /api/v1/packagesreturns{ "success": true, ... }JSONindex.htmlContext from CHANGELOG
From
apps/studio/CHANGELOG.md, version 3.2.9 introduced:And version 3.2.10:
The current
server/index.ts+bundle-api.mjsapproach was the latest evolution, but the Vercel function resolution is broken.Important Notes
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: 部署到 vercel 后, api 错误的返回了html https://play.objectstack.ai/api/v1/packageshttps://play.objectstack.ai/api/v1/meta
Assistant:
Let me start by understanding the repository s...
This pull request was created from Copilot chat.