@@ -97,7 +97,10 @@ export function getCloudflareContext<
97
97
}
98
98
99
99
if ( options . async ) {
100
- return getAndSetCloudflareContextInNodejs ( ) ;
100
+ return getCloudflareContextFromWrangler < CfProperties , Context > ( ) . then ( ( context ) => {
101
+ addCloudflareContextToNodejsGlobal ( context ) ;
102
+ return context ;
103
+ } ) ;
101
104
}
102
105
103
106
// the cloudflare context is initialized by the worker and is always present in production/preview
@@ -159,7 +162,10 @@ function shouldContextInitializationRun(): boolean {
159
162
*
160
163
* @param cloudflareContext the cloudflare context to add to the node.sj global scope
161
164
*/
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 > ) {
163
169
const global = globalThis as InternalGlobalThis < CfProperties , Context > ;
164
170
global [ cloudflareContextSymbol ] = cloudflareContext ;
165
171
}
@@ -219,19 +225,3 @@ async function getCloudflareContextFromWrangler<
219
225
ctx : ctx as Context ,
220
226
} ;
221
227
}
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