diff options
author | 2022-11-08 21:54:49 +0800 | |
---|---|---|
committer | 2022-11-08 21:54:49 +0800 | |
commit | a79a37cad549b21f91599ff86899e456d9dcc7df (patch) | |
tree | f1fe4c030558e505f06a95864ae780365cefebf4 /packages/integrations/cloudflare/src/util.ts | |
parent | 7f3b0398e0350d268f5d07fa2d2520efed7af9be (diff) | |
download | astro-a79a37cad549b21f91599ff86899e456d9dcc7df.tar.gz astro-a79a37cad549b21f91599ff86899e456d9dcc7df.tar.zst astro-a79a37cad549b21f91599ff86899e456d9dcc7df.zip |
Support environment variables in Cloudflare and Netlify Edge functions (#5301)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations/cloudflare/src/util.ts')
-rw-r--r-- | packages/integrations/cloudflare/src/util.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/src/util.ts b/packages/integrations/cloudflare/src/util.ts new file mode 100644 index 000000000..a44780863 --- /dev/null +++ b/packages/integrations/cloudflare/src/util.ts @@ -0,0 +1,16 @@ +export function getProcessEnvProxy() { + return new Proxy( + {}, + { + get: (target, prop) => { + console.warn( + // NOTE: \0 prevents Vite replacement + `Unable to access \`import.meta\0.env.${prop.toString()}\` on initialization ` + + `as the Cloudflare platform only provides the environment variables per request. ` + + `Please move the environment variable access inside a function ` + + `that's only called after a request has been received.` + ); + }, + } + ); +} |