@@ -31,18 +31,24 @@ export function getExpectedRedirectStatus(response: ResponseStub): number {
3131export function createBaseHandler (
3232 fn : ( context : PageEvent ) => unknown ,
3333 createPageEvent : ( event : FetchEvent ) => Promise < PageEvent > ,
34- options : HandlerOptions | ( ( context : PageEvent ) => HandlerOptions | Promise < HandlerOptions > ) = { }
34+ options : HandlerOptions | ( ( context : PageEvent ) => HandlerOptions | Promise < HandlerOptions > ) = { } ,
35+ routerLoad ?: ( event : FetchEvent ) => Promise < void >
3536) {
3637 return eventHandler ( {
3738 handler : ( e : HTTPEvent ) => {
3839 const event = getFetchEvent ( e ) ;
3940
4041 return provideRequestEvent ( event , async ( ) => {
42+ if ( routerLoad ) {
43+ await routerLoad ( event ) ;
44+ }
45+
4146 // api
4247 const match = matchAPIRoute ( new URL ( event . request . url ) . pathname , event . request . method ) ;
4348 if ( match ) {
4449 const mod = await match . handler . import ( ) ;
45- const fn = event . request . method === "HEAD" ? mod [ "HEAD" ] || mod [ "GET" ] : mod [ event . request . method ] ;
50+ const fn =
51+ event . request . method === "HEAD" ? mod [ "HEAD" ] || mod [ "GET" ] : mod [ event . request . method ] ;
4652 ( event as APIEvent ) . params = match . params || { } ;
4753 // @ts -ignore
4854 sharedConfig . context = { event } ;
@@ -62,6 +68,7 @@ export function createBaseHandler(
6268 const mode = resolvedOptions . mode || "stream" ;
6369 // @ts -ignore
6470 if ( resolvedOptions . nonce ) context . nonce = resolvedOptions . nonce ;
71+
6572 if ( mode === "sync" || ! import . meta. env . START_SSR ) {
6673 const html = renderToString ( ( ) => {
6774 ( sharedConfig . context as any ) . event = context ;
@@ -130,7 +137,8 @@ function handleStreamCompleteRedirect(context: PageEvent) {
130137 */
131138export function createHandler (
132139 fn : ( context : PageEvent ) => unknown ,
133- options ?: HandlerOptions | ( ( context : PageEvent ) => HandlerOptions | Promise < HandlerOptions > )
140+ options ?: HandlerOptions | ( ( context : PageEvent ) => HandlerOptions | Promise < HandlerOptions > ) ,
141+ routerLoad ?: ( event : FetchEvent ) => Promise < void >
134142) {
135- return createBaseHandler ( fn , createPageEvent , options ) ;
143+ return createBaseHandler ( fn , createPageEvent , options , routerLoad ) ;
136144}
0 commit comments