-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support environment variables in Cloudflare and Netlify Edge functions #5301
Changes from all commits
9d257e5
0c1acad
785f946
b1e95e1
a10dda7
5d3dcf5
b64bd3a
e7cdfe7
d043e59
c24d46b
6619124
909ac48
7b718d2
64b659b
3976513
1786959
8083f30
9da8e82
ebb0902
43303e3
1588796
1216d9c
aaf3798
b30d076
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Improve environment variable handling performance |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/cloudflare': patch | ||
--- | ||
|
||
Fix environment variables usage in worker output and warn if environment variables are accessedd too early |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/netlify': patch | ||
--- | ||
|
||
Fix environment variables usage in edge functions |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function getProcessEnvProxy() { | ||
return new Proxy( | ||
{}, | ||
{ | ||
get: (target, prop) => { | ||
console.warn( | ||
// NOTE: \0 prevents Vite replacement | ||
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. WHAT! I totally missed this. That's very smart. 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's slightly leaning towards a hack that should be fixed in Vite 4 (hopefully) 😬 |
||
`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.` | ||
); | ||
}, | ||
} | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
<div id="env">{import.meta.env.SECRET_STUFF}</div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# for tests only | ||
|
||
[vars] | ||
SECRET_STUFF = "secret" |
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.
Greatly appreciate these refactors! I knew this plugin was messy and never had time to come back and clean it up. 🎉