File tree Expand file tree Collapse file tree 1 file changed +16
-14
lines changed
packages/start/src/server Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -43,21 +43,23 @@ export function createBaseHandler(
4343 const mod = await match . handler . import ( ) ;
4444 const fn =
4545 event . request . method === "HEAD" ? mod [ "HEAD" ] || mod [ "GET" ] : mod [ event . request . method ] ;
46- ( event as APIEvent ) . params = match . params || { } ;
47- // @ts -expect-error
48- sharedConfig . context = { event } ;
49- const res = await fn ! ( event ) ;
50- if ( res !== undefined ) {
51- if ( res instanceof Response ) return produceResponseWithEventHeaders ( res ) ;
52-
53- return res ;
46+ if ( typeof fn === "function" ) {
47+ ( event as APIEvent ) . params = match . params || { } ;
48+ // @ts -expect-error
49+ sharedConfig . context = { event } ;
50+ const res = await fn ( event ) ;
51+ if ( res !== undefined ) {
52+ if ( res instanceof Response ) return produceResponseWithEventHeaders ( res ) ;
53+
54+ return res ;
55+ }
56+ if ( event . request . method !== "GET" ) {
57+ throw new Error (
58+ `API handler for ${ event . request . method } "${ event . request . url } " did not return a response.` ,
59+ ) ;
60+ }
61+ if ( ! match . isPage ) return ;
5462 }
55- if ( event . request . method !== "GET" ) {
56- throw new Error (
57- `API handler for ${ event . request . method } "${ event . request . url } " did not return a response.` ,
58- ) ;
59- }
60- if ( ! match . isPage ) return ;
6163 }
6264
6365 const context = await createPageEvent ( event ) ;
You can’t perform that action at this time.
0 commit comments