Duplicates
Latest version
Current behavior 😯
When server.baseURL is configured in the Vinxi/SolidStart config (e.g. server: { baseURL: '/admin' }), API routes defined in src/routes/ are never matched. Requests to /admin/api/my-route fall through to the page renderer and return a 404 HTML response instead of executing the API handler.
The root cause is in @solidjs/start/dist/server/handler.js:
// line 29
const match = matchAPIRoute(new URL(event.request.url).pathname, event.request.method)
event.request.url contains the full pathname including the baseURL prefix — e.g. /admin/api/my-route. However, matchAPIRoute looks up routes registered from the file system, which are stored without the prefix (e.g. /api/my-route). The lookup always fails, so all API routes become unreachable.
Expected behavior 🤔
API routes defined in src/routes/api/ should be matched and executed correctly regardless of the server.baseURL setting. matchAPIRoute should strip the server.baseURL prefix from the pathname before performing the route lookup — the same way @solidjs/router's base prop strips it for page route matching on the client.
Steps to reproduce 🕹
Steps:
- Create a SolidStart app with
server.baseURL set:
// app.config.ts
import { defineConfig } from '@solidjs/start/config'
export default defineConfig({
server: { baseURL: '/app' },
})
- Add
base to the Router so page navigation works:
// src/app.tsx
<Router base={import.meta.env.SERVER_BASE_URL}>
<FileRoutes />
</Router>
- Create an API route:
// src/routes/api/hello.ts
export function GET() {
return new Response(JSON.stringify({ ok: true }), {
headers: { 'Content-Type': 'application/json' },
})
}
- Start the dev server and request
GET /app/api/hello
Result: 404 — the SPA catch-all ([...404]) renders instead of the API handler.
Expected: 200 { "ok": true }
Context 🔦
Workaround: Move the route file to mirror the full path including the base — src/routes/app/api/hello.ts — so the registered route path /app/api/hello matches what matchAPIRoute receives. This is unergonomic and forces duplication of the base prefix in the file structure.
Your environment 🌎
Duplicates
Latest version
Current behavior 😯
When
server.baseURLis configured in the Vinxi/SolidStart config (e.g.server: { baseURL: '/admin' }), API routes defined insrc/routes/are never matched. Requests to/admin/api/my-routefall through to the page renderer and return a 404 HTML response instead of executing the API handler.The root cause is in
@solidjs/start/dist/server/handler.js:event.request.urlcontains the full pathname including thebaseURLprefix — e.g./admin/api/my-route. However,matchAPIRoutelooks up routes registered from the file system, which are stored without the prefix (e.g./api/my-route). The lookup always fails, so all API routes become unreachable.Expected behavior 🤔
API routes defined in
src/routes/api/should be matched and executed correctly regardless of theserver.baseURLsetting.matchAPIRouteshould strip theserver.baseURLprefix from the pathname before performing the route lookup — the same way@solidjs/router'sbaseprop strips it for page route matching on the client.Steps to reproduce 🕹
Steps:
server.baseURLset:baseto the Router so page navigation works:GET /app/api/helloResult:
404— the SPA catch-all ([...404]) renders instead of the API handler.Expected:
200 { "ok": true }Context 🔦
Workaround: Move the route file to mirror the full path including the base —
src/routes/app/api/hello.ts— so the registered route path/app/api/hellomatches whatmatchAPIRoutereceives. This is unergonomic and forces duplication of the base prefix in the file structure.Your environment 🌎