summaryrefslogtreecommitdiff
path: root/examples/env-vars/src/scripts/client.ts
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-02-18 16:06:56 -0600
committerGravatar GitHub <noreply@github.com> 2022-02-18 16:06:56 -0600
commit39cbe5008549517d9360bc7c473793523c0c9207 (patch)
treefe6b2e7c6bf6defbbc80d7e0eb45341fd3c18881 /examples/env-vars/src/scripts/client.ts
parent37d4dd8d57d5423f2d099f9eb81b5b41b6d69403 (diff)
downloadastro-39cbe5008549517d9360bc7c473793523c0c9207.tar.gz
astro-39cbe5008549517d9360bc7c473793523c0c9207.tar.zst
astro-39cbe5008549517d9360bc7c473793523c0c9207.zip
Expose private `.env` variables to `import.meta.env` during SSR (#2612)
* chore(examples): add env-vars example * feat: improve import.meta.env support * chore: add changeset * test: update astro-envs test * refactor: cleanup code based on feedback * fix: import.meta guard * fix: update memory test threshold to 10%
Diffstat (limited to 'examples/env-vars/src/scripts/client.ts')
-rw-r--r--examples/env-vars/src/scripts/client.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/examples/env-vars/src/scripts/client.ts b/examples/env-vars/src/scripts/client.ts
new file mode 100644
index 000000000..05961d399
--- /dev/null
+++ b/examples/env-vars/src/scripts/client.ts
@@ -0,0 +1,9 @@
+(() => {
+ const { SSR, DB_PASSWORD, PUBLIC_SOME_KEY } = import.meta.env;
+
+ // DB_PASSWORD is NOT available because we're running on the client
+ console.log({ SSR, DB_PASSWORD });
+
+ // PUBLIC_SOME_KEY is available everywhere
+ console.log({ SSR, PUBLIC_SOME_KEY });
+})()