@@ -12,62 +12,65 @@ import {
1212 convertToQueryString ,
1313} from "../core/routing/util" ;
1414
15- globalThis . __als = new AsyncLocalStorage ( ) ;
15+ globalThis . __openNextAls = new AsyncLocalStorage ( ) ;
1616
1717const defaultHandler = async (
1818 internalEvent : InternalEvent ,
1919) : Promise < InternalResult > => {
2020 globalThis . isEdgeRuntime = true ;
2121
2222 // We run everything in the async local storage context so that it is available in edge runtime functions
23- return runWithOpenNextRequestContext ( false , async ( ) => {
24- const host = internalEvent . headers . host
25- ? `https://${ internalEvent . headers . host } `
26- : "http://localhost:3000" ;
27- const initialUrl = new URL ( internalEvent . rawPath , host ) ;
28- initialUrl . search = convertToQueryString ( internalEvent . query ) ;
29- const url = initialUrl . toString ( ) ;
23+ return runWithOpenNextRequestContext (
24+ { isISRRevalidation : false } ,
25+ async ( ) => {
26+ const host = internalEvent . headers . host
27+ ? `https://${ internalEvent . headers . host } `
28+ : "http://localhost:3000" ;
29+ const initialUrl = new URL ( internalEvent . rawPath , host ) ;
30+ initialUrl . search = convertToQueryString ( internalEvent . query ) ;
31+ const url = initialUrl . toString ( ) ;
3032
31- // @ts -expect-error - This is bundled
32- const handler = await import ( `./middleware.mjs` ) ;
33+ // @ts -expect-error - This is bundled
34+ const handler = await import ( `./middleware.mjs` ) ;
3335
34- const response : Response = await handler . default ( {
35- headers : internalEvent . headers ,
36- method : internalEvent . method || "GET" ,
37- nextConfig : {
38- basePath : NextConfig . basePath ,
39- i18n : NextConfig . i18n ,
40- trailingSlash : NextConfig . trailingSlash ,
41- } ,
42- url,
43- body : convertBodyToReadableStream (
44- internalEvent . method ,
45- internalEvent . body ,
46- ) ,
47- } ) ;
48- const responseHeaders : Record < string , string | string [ ] > = { } ;
49- response . headers . forEach ( ( value , key ) => {
50- if ( key . toLowerCase ( ) === "set-cookie" ) {
51- responseHeaders [ key ] = responseHeaders [ key ]
52- ? [ ...responseHeaders [ key ] , value ]
53- : [ value ] ;
54- } else {
55- responseHeaders [ key ] = value ;
56- }
57- } ) ;
36+ const response : Response = await handler . default ( {
37+ headers : internalEvent . headers ,
38+ method : internalEvent . method || "GET" ,
39+ nextConfig : {
40+ basePath : NextConfig . basePath ,
41+ i18n : NextConfig . i18n ,
42+ trailingSlash : NextConfig . trailingSlash ,
43+ } ,
44+ url,
45+ body : convertBodyToReadableStream (
46+ internalEvent . method ,
47+ internalEvent . body ,
48+ ) ,
49+ } ) ;
50+ const responseHeaders : Record < string , string | string [ ] > = { } ;
51+ response . headers . forEach ( ( value , key ) => {
52+ if ( key . toLowerCase ( ) === "set-cookie" ) {
53+ responseHeaders [ key ] = responseHeaders [ key ]
54+ ? [ ...responseHeaders [ key ] , value ]
55+ : [ value ] ;
56+ } else {
57+ responseHeaders [ key ] = value ;
58+ }
59+ } ) ;
5860
59- const body =
60- ( response . body as ReadableStream < Uint8Array > ) ?? emptyReadableStream ( ) ;
61+ const body =
62+ ( response . body as ReadableStream < Uint8Array > ) ?? emptyReadableStream ( ) ;
6163
62- return {
63- type : "core" ,
64- statusCode : response . status ,
65- headers : responseHeaders ,
66- body : body ,
67- // Do we need to handle base64 encoded response?
68- isBase64Encoded : false ,
69- } ;
70- } ) ;
64+ return {
65+ type : "core" ,
66+ statusCode : response . status ,
67+ headers : responseHeaders ,
68+ body : body ,
69+ // Do we need to handle base64 encoded response?
70+ isBase64Encoded : false ,
71+ } ;
72+ } ,
73+ ) ;
7174} ;
7275
7376export const handler = await createGenericHandler ( {
0 commit comments