0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-10 22:38:53 -05:00
astro/.changeset/eighty-boxes-applaud.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.4 KiB
Markdown
Raw Normal View History

2024-08-13 14:21:44 +02:00
---
'astro': major
---
2024-08-15 16:59:57 +02:00
The `astro:env` feature introduced behind a flag in [v4.10.0](https://github.com/withastro/astro/blob/main/packages/astro/CHANGELOG.md#x4100) is no longer experimental and is available for general use.
2024-08-13 14:21:44 +02:00
2024-08-15 16:59:57 +02:00
This feature lets you configure a type-safe schema for your environment variables, and indicate whether they should be available on the server or the client. Import and use your defined variables from the appropriate `/client` or `/server` module:
```astro
---
import { API_URL } from "astro:env/client"
import { API_SECRET_TOKEN } from "astro:env/server"
const data = await fetch(`${API_URL}/users`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_SECRET_TOKEN}`
},
})
---
<script>
import { API_URL } from "astro:env/client"
fetch(`${API_URL}/ping`)
</script>
```
If you were previously using this feature, please remove the experimental flag from your Astro config:
2024-08-13 14:21:44 +02:00
```diff
import { defineConfig, envField } from 'astro/config'
export default defineConfig({
2024-08-15 14:17:53 +02:00
- experimental: {
2024-08-15 16:59:57 +02:00
- env: {
- schema: {
- FOO: envField.string({ /* ... */ })
- }
- }
2024-08-15 14:17:53 +02:00
- }
2024-08-15 16:59:57 +02:00
+ env: {
+ schema: {
+ FOO: envField.string({ /* ... */ })
+ }
+ }
2024-08-13 14:21:44 +02:00
})
2024-08-15 16:59:57 +02:00
```
If you have been waiting for stabilization before using `astro:env`, you can now do so.
Please see [Using environment variables](https://docs.astro.build/en/guides/environment-variables/#astroenv) for more about this feature.