0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

Discard changes to .changeset/eighty-boxes-applaud.md

This commit is contained in:
Florian Lefebvre 2024-08-22 17:30:32 +02:00 committed by GitHub
parent 5da612e546
commit fb2f2a62c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,9 +2,27 @@
'astro': major
---
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.
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. If you have been waiting for stabilization before using `astro:env`, you can now do so.
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:
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.
To configure a schema, add the `env` option to your Astro config and define your client and server variables. If you were previously using this feature, please remove the experimental flag from your Astro config and move your entire `env` configuration unchanged to a top-level option.
```js
import { defineConfig, envField } from 'astro/config'
export default defineConfig({
env: {
schema: {
API_URL: envField.string({ context: "client", access: "public", optional: true }),
PORT: envField.number({ context: "server", access: "public", default: 4321 }),
API_SECRET: envField.string({ context: "server", access: "secret" }),
}
}
})
```
You can import and use your defined variables from the appropriate `/client` or `/server` module:
```astro
---
@ -27,27 +45,4 @@ fetch(`${API_URL}/ping`)
</script>
```
If you were previously using this feature, please remove the experimental flag from your Astro config:
```diff
import { defineConfig, envField } from 'astro/config'
export default defineConfig({
- experimental: {
- env: {
- schema: {
- FOO: envField.string({ /* ... */ })
- }
- }
- }
+ env: {
+ schema: {
+ FOO: envField.string({ /* ... */ })
+ }
+ }
})
```
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.
Please see our [guide to using environment variables](https://docs.astro.build/en/guides/environment-variables/#astroenv) for more about this feature.