solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

[Bug?]: Configuring `server.baseURL` will make the `api` route inaccessible

Open thinke5 opened this issue 9 months ago • 0 comments

Duplicates

  • [x] I have searched the existing issues

Latest version

  • [x] I have tested the latest version

Current behavior 😯

Image

Expected behavior 🤔

Image

Steps to reproduce 🕹

Steps:

  1. Configuring app.config.ts
defineConfig({
  server: {
    baseURL:"/the_project",
  },
});

  1. Create a file src/routes/api/info.ts
import type { APIHandler } from '@solidjs/start/server';

export const POST: APIHandler = async (event) => {
  return {
    name: 'John POST',
  };
};

  1. fetch api
fetch("/the_project/api/info", {
  "method": "POST",
});

Context 🔦

After debugging, I think the bug is here

https://github.com/solidjs/solid-start/blob/28e3fc5030b4a4eb06c7e3b17bd17569f4873b14/packages/start/src/server/handler.ts#L47

new URL(event.request.url).pathname = /the_project/api/info ,but in router is /api/info

https://github.com/solidjs/solid-start/blob/28e3fc5030b4a4eb06c7e3b17bd17569f4873b14/packages/start/src/router/routes.ts#L61

After modification, it can run normally

const match = matchAPIRoute(event.nativeEvent.path, event.request.method);

Your environment 🌎


thinke5 avatar Mar 19 '25 04:03 thinke5