Skip to content

fix: strip baseURL prefix before matching API routes#2117

Open
themavik wants to merge 2 commits intosolidjs:mainfrom
themavik:fix/2106-api-routes-base-url
Open

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

Conversation

@themavik
Copy link

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
Copy link

netlify bot commented Mar 19, 2026

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

Name Link
🔨 Latest commit 638dfff
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/69bbf9887c475c00084c7f9c
😎 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
Copy link

changeset-bot bot commented Mar 19, 2026

⚠️ No Changeset found

Latest commit: 638dfff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

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: 638dfff

Copy link
Author

@themavik themavik left a comment

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
Copy link
Contributor

brenelz commented Mar 19, 2026

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

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