File tree Expand file tree Collapse file tree 7 files changed +67
-3
lines changed
Expand file tree Collapse file tree 7 files changed +67
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @solidjs/start " : patch
3+ ---
4+
5+ 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.
Original file line number Diff line number Diff line change @@ -60,14 +60,27 @@ function defineRoutes(fileRoutes: Route[]) {
6060export function matchAPIRoute ( path : string , method : string ) {
6161 const match = router . lookup ( path ) ;
6262 if ( match && match . route ) {
63- const handler =
64- method === "HEAD" ? match . route [ "$HEAD" ] || match . route [ "$GET" ] : match . route [ `$${ method } ` ] ;
63+ const route = match . route ;
64+
65+ // Find the appropriate handler for the HTTP method
66+ const handler = method === "HEAD"
67+ ? route . $HEAD || route . $GET
68+ : route [ `$${ method } ` ] ;
69+
6570 if ( handler === undefined ) return ;
71+
72+ // Check if this is a page route
73+ const isPage = route . page === true && route . $component !== undefined ;
74+
75+ // Return comprehensive route information
6676 return {
6777 handler,
68- params : match . params
78+ params : match . params ,
79+ isPage
6980 } ;
7081 }
82+
83+ return undefined ;
7184}
7285
7386function containsHTTP ( route : Route ) {
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ export function createBaseHandler(
5959 `API handler for ${ event . request . method } "${ event . request . url } " did not return a response.`
6060 ) ;
6161 }
62+ if ( ! match . isPage ) return ;
6263 }
6364
6465 // render
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ export default function App() {
5050 < li >
5151 < a href = "/generator-server-function" > generator server function</ a >
5252 </ li >
53+ < li >
54+ < a href = "/not-found" > Not Found</ a >
55+ </ li >
56+ < li >
57+ < a href = "/text-plain-response" > Text Plain Response</ a >
58+ </ li >
5359 < li >
5460 < a href = "/referencing-multiple-export-named-functions-in-the-same-file" > referencing multiple export named functions in the same file</ a >
5561 </ li >
Original file line number Diff line number Diff line change 1+ import { Title } from "@solidjs/meta" ;
2+ import { HttpStatusCode } from "@solidjs/start" ;
3+ import type { APIEvent } from "@solidjs/start/server" ;
4+
5+ export const GET = ( event : APIEvent ) => {
6+ if ( event . request . headers . get ( "accept" ) !== "application/json" ) return ;
7+ return { notFound : "API" } ;
8+ } ;
9+
10+ export default function NotFound ( ) {
11+ return (
12+ < main >
13+ < Title > Not Found</ Title >
14+ < HttpStatusCode code = { 404 } />
15+ < h1 > Page Not Found</ h1 >
16+ < p >
17+ { "Your page cannot be found... >_<" }
18+ </ p >
19+ </ main >
20+ ) ;
21+ }
Original file line number Diff line number Diff line change 1+ export function GET ( e : { nativeEvent : { respondWith : ( arg0 : Response ) => void ; } ; } ) {
2+ e . nativeEvent . respondWith ( new Response ( "test" ) ) ;
3+ }
Original file line number Diff line number Diff line change 1+ export default function App ( ) {
2+ const handleClick = ( e : Event ) => {
3+ // e.preventDefault();
4+
5+ window . location . href = "/api/text-plain" ;
6+ } ;
7+
8+ return (
9+ < main >
10+ < a href = "/api/text-plain" onClick = { handleClick } >
11+ Text Plain Response
12+ </ a >
13+ </ main >
14+ ) ;
15+ } ;
You can’t perform that action at this time.
0 commit comments