@@ -31,18 +31,24 @@ export function getExpectedRedirectStatus(response: ResponseStub): number {
31
31
export function createBaseHandler (
32
32
fn : ( context : PageEvent ) => unknown ,
33
33
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 >
35
36
) {
36
37
return eventHandler ( {
37
38
handler : ( e : HTTPEvent ) => {
38
39
const event = getFetchEvent ( e ) ;
39
40
40
41
return provideRequestEvent ( event , async ( ) => {
42
+ if ( routerLoad ) {
43
+ await routerLoad ( event ) ;
44
+ }
45
+
41
46
// api
42
47
const match = matchAPIRoute ( new URL ( event . request . url ) . pathname , event . request . method ) ;
43
48
if ( match ) {
44
49
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 ] ;
46
52
( event as APIEvent ) . params = match . params || { } ;
47
53
// @ts -ignore
48
54
sharedConfig . context = { event } ;
@@ -62,6 +68,7 @@ export function createBaseHandler(
62
68
const mode = resolvedOptions . mode || "stream" ;
63
69
// @ts -ignore
64
70
if ( resolvedOptions . nonce ) context . nonce = resolvedOptions . nonce ;
71
+
65
72
if ( mode === "sync" || ! import . meta. env . START_SSR ) {
66
73
const html = renderToString ( ( ) => {
67
74
( sharedConfig . context as any ) . event = context ;
@@ -130,7 +137,8 @@ function handleStreamCompleteRedirect(context: PageEvent) {
130
137
*/
131
138
export function createHandler (
132
139
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 >
134
142
) {
135
- return createBaseHandler ( fn , createPageEvent , options ) ;
143
+ return createBaseHandler ( fn , createPageEvent , options , routerLoad ) ;
136
144
}
0 commit comments