@@ -97,7 +97,10 @@ export function getCloudflareContext<
9797 }
9898
9999 if ( options . async ) {
100- return getAndSetCloudflareContextInNodejs ( ) ;
100+ return getCloudflareContextFromWrangler < CfProperties , Context > ( ) . then ( ( context ) => {
101+ addCloudflareContextToNodejsGlobal ( context ) ;
102+ return context ;
103+ } ) ;
101104 }
102105
103106 // the cloudflare context is initialized by the worker and is always present in production/preview
@@ -159,7 +162,10 @@ function shouldContextInitializationRun(): boolean {
159162 *
160163 * @param cloudflareContext the cloudflare context to add to the node.sj global scope
161164 */
162- function addCloudflareContextToNodejsGlobal ( cloudflareContext : CloudflareContext < CfProperties , Context > ) {
165+ function addCloudflareContextToNodejsGlobal <
166+ CfProperties extends Record < string , unknown > = IncomingRequestCfProperties ,
167+ Context = ExecutionContext ,
168+ > ( cloudflareContext : CloudflareContext < CfProperties , Context > ) {
163169 const global = globalThis as InternalGlobalThis < CfProperties , Context > ;
164170 global [ cloudflareContextSymbol ] = cloudflareContext ;
165171}
@@ -219,19 +225,3 @@ async function getCloudflareContextFromWrangler<
219225 ctx : ctx as Context ,
220226 } ;
221227}
222-
223- /**
224- * Gets a local proxy version of the cloudflare context (created using `getPlatformProxy`) when running
225- * in a Node.js process (so under `next dev` or for ssg under `next build`), is also sets this value on the
226- * globalThis so that it can be accessed later.
227- *
228- * @returns the local proxy version of the cloudflare context
229- */
230- async function getAndSetCloudflareContextInNodejs <
231- CfProperties extends Record < string , unknown > = IncomingRequestCfProperties ,
232- Context = ExecutionContext ,
233- > ( ) : Promise < CloudflareContext < CfProperties , Context > > {
234- const context = await getCloudflareContextFromWrangler ( ) ;
235- addCloudflareContextToNodejsGlobal ( context ) ;
236- return context as unknown as CloudflareContext < CfProperties , Context > ;
237- }
0 commit comments