Skip to content

Commit ab413a0

Browse files
committed
chore: add examples for astro:env
1 parent 54d4138 commit ab413a0

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

packages/astro/src/i18n/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export function getLocaleAbsoluteUrl({ site, isBuild, ...rest }: GetLocaleAbsolu
122122
const localeUrl = getLocaleRelativeUrl(rest);
123123
const { domains, locale } = rest;
124124
let url;
125-
console.log('isBuild', domains, isBuild);
126125
if (isBuild && domains && domains[locale]) {
127126
const base = domains[locale];
128127
url = joinPaths(base, localeUrl.replace(`/${rest.locale}`, ''));

packages/integrations/cloudflare/test/fixtures/vite-plugin/astro.config.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import cloudflare from '@astrojs/cloudflare';
3-
import { defineConfig } from 'astro/config';
3+
import { defineConfig, envField } from 'astro/config';
44

55
import mdx from '@astrojs/mdx';
66
import { fileURLToPath } from 'node:url';
@@ -29,4 +29,11 @@ export default defineConfig({
2929
}
3030
},
3131
integrations: [mdx(), react()],
32+
env: {
33+
schema: {
34+
FOO: envField.string({ context: 'server', access: 'public' }),
35+
BAR: envField.string({ context: 'client', access: 'public' }),
36+
SECRET: envField.string({ context: 'server', access: 'secret' }),
37+
}
38+
}
3239
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
import { FOO, SECRET } from "astro:env/server";
3+
import { BAR } from "astro:env/client";
4+
5+
const foo = FOO;
6+
const bar = BAR;
7+
const secret = SECRET;
8+
---
9+
10+
<h1>{foo}</h1>
11+
<h1>{bar}</h1>
12+
<h1>{secret}</h1>
13+
14+
<script>
15+
import { BAR } from "astro:env/client";
16+
17+
console.log(BAR);
18+
</script>

packages/integrations/cloudflare/test/fixtures/vite-plugin/src/pages/index.astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ const { Content } = await render(increment);
1919
<body>
2020
<p>Last updated: {increment.data.lastUpdated.toLocaleTimeString()}</p>
2121

22+
<h2>Translations</h2>
2223
<ul>
2324
<li><a href="/fr">French index</a></li>
2425
</ul>
25-
<h1>Dogs</h1>
26+
<h2><code>astro:env</code></h2>
27+
<a href="/env">Environment variables</a>
28+
<h2>Dogs</h2>
2629
<p>Running on: {workerRuntime ?? 'unknown runtime'}</p>
2730
<div id="framework">
2831
<Hello client:load />

0 commit comments

Comments
 (0)