Page Not Found
++ {"Your page cannot be found... >_<"} +
+diff --git a/.changeset/slow-eagles-wear.md b/.changeset/slow-eagles-wear.md new file mode 100644 index 000000000..0ca32b23b --- /dev/null +++ b/.changeset/slow-eagles-wear.md @@ -0,0 +1,5 @@ +--- +"@solidjs/start": patch +--- + +Enhance route matching to return `isPage` flag and add tests for plain text API response and Missing page handling that has both api/file routes. diff --git a/packages/start/src/router/routes.ts b/packages/start/src/router/routes.ts index de383ac34..fe569b31a 100644 --- a/packages/start/src/router/routes.ts +++ b/packages/start/src/router/routes.ts @@ -60,14 +60,27 @@ function defineRoutes(fileRoutes: Route[]) { export function matchAPIRoute(path: string, method: string) { const match = router.lookup(path); if (match && match.route) { - const handler = - method === "HEAD" ? match.route["$HEAD"] || match.route["$GET"] : match.route[`$${method}`]; + const route = match.route; + + // Find the appropriate handler for the HTTP method + const handler = method === "HEAD" + ? route.$HEAD || route.$GET + : route[`$${method}`]; + if (handler === undefined) return; + + // Check if this is a page route + const isPage = route.page === true && route.$component !== undefined; + + // Return comprehensive route information return { handler, - params: match.params + params: match.params, + isPage }; } + + return undefined; } function containsHTTP(route: Route) { diff --git a/packages/start/src/server/handler.ts b/packages/start/src/server/handler.ts index effd00735..01714c1ac 100644 --- a/packages/start/src/server/handler.ts +++ b/packages/start/src/server/handler.ts @@ -59,6 +59,7 @@ export function createBaseHandler( `API handler for ${event.request.method} "${event.request.url}" did not return a response.` ); } + if (!match.isPage) return; } // render diff --git a/packages/tests/src/app.tsx b/packages/tests/src/app.tsx index 3be335393..fc0916758 100644 --- a/packages/tests/src/app.tsx +++ b/packages/tests/src/app.tsx @@ -50,6 +50,12 @@ export default function App() {
+ {"Your page cannot be found... >_<"} +
+