Skip to content

Commit fd0024e

Browse files
committed
combine variables from a global with the request-scoped env
1 parent ad4aaad commit fd0024e

File tree

1 file changed

+7
-3
lines changed
  • packages/cloudflare/src/cli/templates

1 file changed

+7
-3
lines changed

packages/cloudflare/src/cli/templates/worker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ const cloudflareContextALS = new AsyncLocalStorage<CloudflareContext>();
2121
}
2222
);
2323

24+
declare const __OPENNEXT_BUILD_TIME_ENV: Record<string, string>;
25+
2426
export default {
2527
async fetch(request, env, ctx) {
26-
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, async () => {
28+
const combinedEnv = { ...__OPENNEXT_BUILD_TIME_ENV, ...env };
29+
30+
return cloudflareContextALS.run({ env: combinedEnv, ctx, cf: request.cf }, async () => {
2731
// Set the default Origin for the origin resolver.
2832
const url = new URL(request.url);
2933
process.env.OPEN_NEXT_ORIGIN = JSON.stringify({
@@ -37,13 +41,13 @@ export default {
3741
// The Middleware handler can return either a `Response` or a `Request`:
3842
// - `Response`s should be returned early
3943
// - `Request`s are handled by the Next server
40-
const reqOrResp = await middlewareHandler(request, env, ctx);
44+
const reqOrResp = await middlewareHandler(request, combinedEnv, ctx);
4145

4246
if (reqOrResp instanceof Response) {
4347
return reqOrResp;
4448
}
4549

46-
return serverHandler(reqOrResp, env, ctx);
50+
return serverHandler(reqOrResp, combinedEnv, ctx);
4751
});
4852
},
4953
} as ExportedHandler<{ ASSETS: Fetcher }>;

0 commit comments

Comments
 (0)