Skip to content

fix(api): route /api requests consistently for Vercel deployments (#21) - #50

Open
produckq-boop wants to merge 1 commit into
octraban:mainfrom
produckq-boop:fix/vercel-api-routing
Open

produckq-boop wants to merge 1 commit into
octraban:mainfrom
produckq-boop:fix/vercel-api-routing

Conversation

@produckq-boop

Copy link
Copy Markdown

Problem

On Vercel, the static deployment has no local /api/ proxy like Vite's dev server or Docker's nginx.conf. In addition, several callers (BackendStatusBanner, ExportButton, SimulateButton, useEventStream, useTxStatus, and sandbox-api) bypassed resolveApiBase() in src/api.ts with hardcoded /api/... paths or window.location.host WebSocket URLs, so setting VITE_API_URL on Vercel still left health checks, SSE streams, exports, simulations, and sandbox endpoints hitting the static host and failing.

Changes

  • vercel.json: Tighten the SPA rewrite regex to /((?!api(?:/|$)).*) -> /index.html so both /api and /api/* are excluded from the HTML fallback when unconfigured.
  • src/api.ts: Normalize trailing slashes and /api suffixes in resolveApiBase(), and add buildApiUrl() and resolveWsUrl() so REST, SSE, and WebSocket callers resolve against VITE_API_URL when set and fall back to relative /api (or window.location) in dev and Docker/nginx.
  • Call-site alignment: Route BackendStatusBanner, ExportButton, SimulateButton, useEventStream, useTxStatus, and sandbox-api through buildApiUrl() / resolveWsUrl(), and reject text/html fallback responses in BackendStatusBanner.checkHealth().
  • Docs & env template: Document all three deployment targets (Vite dev proxy, Docker/nginx, and Vercel via VITE_API_URL or /api/:path* rewrite) in README.md and align .env.example.
  • Tests: Expand test/api-base.test.ts and test/BackendStatusBanner.test.tsx to cover resolveApiBase, buildApiUrl, resolveWsUrl, sandbox-api paths, VITE_API_URL health checks, and HTML fallback rejection.

Testing

  • npm run lint (0 errors)
  • npx tsc --noEmit (clean)
  • npm run build (passes)
  • npm test (20 test files, 174 tests passed)

Closes #21

@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

@produckq-boop is attempting to deploy a commit to the Prisca's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vercel deployment has no backend route for /api requests

1 participant