Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-ladybugs-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Handle base url in api routes
10 changes: 7 additions & 3 deletions packages/start/src/server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ export function createBaseHandler(
handler: decorateHandler(async (e: H3Event) => {
const event = getRequestEvent()!;
const url = new URL(event.request.url);
const pathname = url.pathname;
const pathname = stripBaseUrl(url.pathname);

const serverFunctionTest = join(import.meta.env.BASE_URL, SERVER_FN_BASE);
if (pathname.startsWith(serverFunctionTest)) {
if (pathname.startsWith(SERVER_FN_BASE)) {
const serverFnResponse = await handleServerFunction(e);

if (serverFnResponse instanceof Response)
Expand Down Expand Up @@ -265,3 +264,8 @@ function produceResponseWithEventHeaders(res: Response) {

return ret
}

function stripBaseUrl(path: string) {
if(import.meta.env.BASE_URL === "/" || import.meta.env.BASE_URL === "") return path;
return path.slice(import.meta.env.BASE_URL.length);
}
Loading