-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use ALS for process.env
object
#98
Changes from 1 commit
335fac5
627d10b
e7f9206
4be38fa
4628b62
9ecefdf
d3a2bde
9f13e52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ const cloudflareContextALS = new AsyncLocalStorage<CloudflareContext>(); | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(globalThis as any)[Symbol.for("__cloudflare-context__")] = createALSProxy(cloudflareContextALS); | ||
|
||
const originalEnv: Partial<typeof process.env> = { ...globalThis.process.env }; | ||
// @ts-expect-error - populated when we run inside the ALS context | ||
globalThis.process.env = createALSProxy(processEnvALS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I agree with @vicb to some extent here. E.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to add tests. (I think we should requires them in the PR template, as well as repro on issue templat - well we have to add those templates first, I can take care of that next week) |
||
|
||
|
@@ -30,7 +31,7 @@ let requestHandler: NodeRequestHandler | null = null; | |
|
||
export default { | ||
async fetch(request, env, ctx) { | ||
return processEnvALS.run({ NODE_ENV: "production", ...env }, () => { | ||
return processEnvALS.run({ NODE_ENV: "production", ...originalEnv, ...env }, () => { | ||
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, async () => { | ||
if (requestHandler == null) { | ||
// Note: "next/dist/server/next-server" is a cjs module so we have to `require` it not to confuse esbuild | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to clone this object here? We make a copy of the
originalEnv
when setting up the ALS.