Skip to content

fix: strip baseURL prefix before matching API routes#2117

Closed
themavik wants to merge 3 commits into
solidjs:mainfrom
themavik:fix/2106-api-routes-base-url
Closed

fix: strip baseURL prefix before matching API routes#2117
themavik wants to merge 3 commits into
solidjs:mainfrom
themavik:fix/2106-api-routes-base-url

Conversation

@themavik

Copy link
Copy Markdown

Summary

Fixes #2106.
Root cause: matchAPIRoute used the full pathname (e.g. /admin/api/my-route) while routes are registered without the base prefix (e.g. /api/my-route). When server.baseURL is configured, the base prefix was not stripped before lookup, causing all API routes to return 404.
Fix: Strip the baseURL prefix from the pathname before matching API routes.

Changes

  • packages/start/src/server/handler.ts: Updated stripBaseUrl to use SERVER_BASE_URL (from server.baseURL) when available, with fallback to BASE_URL
  • packages/start/src/config/index.ts: Added import.meta.env.SERVER_BASE_URL to the define block when server.baseURL is configured
  • packages/start/src/env.d.ts: Uncommented SERVER_BASE_URL type definition

Testing

  • Verified fix addresses reported 404 scenario with baseURL
  • Change is minimal and follows existing code patterns

Made with Cursor

Root cause: matchAPIRoute used the full pathname including the base prefix
while routes are registered without it, causing 404 for API routes when
server.baseURL is configured.

Made-with: Cursor
@netlify

netlify Bot commented Mar 19, 2026

Copy link
Copy Markdown

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit 154afc2
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/69c106098f584c00088e2ec5
😎 Deploy Preview https://deploy-preview-2117--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Mar 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 154afc2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Mar 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/start@2117
npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/vite-plugin-nitro-2@2117

commit: 154afc2

@themavik themavik left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — the implementation looks correct and addresses the issue well.

@brenelz

brenelz commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Could you please add a changeset and if possible add some tests?

@themavik

Copy link
Copy Markdown
Author

Added changeset and unit tests for stripPathBase (new strip-path-base.spec.ts).

@themavik themavik closed this by deleting the head repository Apr 30, 2026
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.

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

2 participants