Skip to content

Commit 9f13e52

Browse files
committed
capture original process.env value
1 parent d3a2bde commit 9f13e52

File tree

1 file changed

+2
-1
lines changed
  • packages/cloudflare/src/cli/templates

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const cloudflareContextALS = new AsyncLocalStorage<CloudflareContext>();
2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2121
(globalThis as any)[Symbol.for("__cloudflare-context__")] = createALSProxy(cloudflareContextALS);
2222

23+
const originalEnv: Partial<typeof process.env> = { ...globalThis.process.env };
2324
// @ts-expect-error - populated when we run inside the ALS context
2425
globalThis.process.env = createALSProxy(processEnvALS);
2526

@@ -30,7 +31,7 @@ let requestHandler: NodeRequestHandler | null = null;
3031

3132
export default {
3233
async fetch(request, env, ctx) {
33-
return processEnvALS.run({ NODE_ENV: "production", ...env }, () => {
34+
return processEnvALS.run({ NODE_ENV: "production", ...originalEnv, ...env }, () => {
3435
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, async () => {
3536
if (requestHandler == null) {
3637
// Note: "next/dist/server/next-server" is a cjs module so we have to `require` it not to confuse esbuild

0 commit comments

Comments
 (0)