Skip to content

[Bug?]: API routes not matched when server.baseURL is set #2106

Description

@DemonStore

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the 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:

  1. Create a SolidStart app with server.baseURL set:
// app.config.ts
import { defineConfig } from '@solidjs/start/config'
export default defineConfig({
  server: { baseURL: '/app' },
})
  1. Add base to the Router so page navigation works:
// src/app.tsx
<Router base={import.meta.env.SERVER_BASE_URL}>
  <FileRoutes />
</Router>
  1. Create an API route:
// src/routes/api/hello.ts
export function GET() {
  return new Response(JSON.stringify({ ok: true }), {
    headers: { 'Content-Type': 'application/json' },
  })
}
  1. 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 🌎

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.xtargeting SolidStart 2.x versionsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions