-
-
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
chore: improve astro:env docs #11653
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Updates `astro:env` docs to reflect current developments and usage guidance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1985,25 +1985,29 @@ export interface AstroUserConfig { | |
* @version 4.10.0 | ||
* @description | ||
* | ||
* Enables experimental `astro:env` features . | ||
* Enables experimental `astro:env` features. | ||
* | ||
* The `astro:env` API 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 { APP_ID } from "astro:env/client" | ||
* import { API_URL, API_TOKEN, getSecret } from "astro:env/server" | ||
* const NODE_ENV = getSecret("NODE_ENV") | ||
* import { API_URL } from "astro:env/client" | ||
* import { API_SECRET_TOKEN } from "astro:env/server" | ||
* | ||
* const data = await fetch(`${API_URL}/users`, { | ||
* method: "POST", | ||
* method: "GET", | ||
* headers: { | ||
* "Content-Type": "application/json", | ||
* "Authorization": `Bearer ${API_TOKEN}` | ||
* "Authorization": `Bearer ${API_SECRET_TOKEN}` | ||
* }, | ||
* body: JSON.stringify({ appId: APP_ID, nodeEnv: NODE_ENV }) | ||
* }) | ||
* --- | ||
* | ||
* <script> | ||
* import { API_URL } from "astro:env/client" | ||
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. Also showing in a client script so users understand a client var can be accessed on both client and server |
||
* | ||
* fetch(`${API_URL}/ping`) | ||
* </script> | ||
* ``` | ||
* | ||
* To define the data type and properties of your environment variables, declare a schema in your Astro config in `experimental.env.schema`. The `envField` helper allows you define your variable as a string, number, or boolean and pass properties in an object: | ||
|
@@ -2041,7 +2045,7 @@ export interface AstroUserConfig { | |
* import { PORT } from "astro:env/server" | ||
* ``` | ||
* | ||
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `astro:env/server` module. The `getSecret()` helper function can be used to retrieve secrets not specified in the schema: | ||
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `astro:env/server` module. The `getSecret()` helper function can be used to retrieve secrets not specified in the schema. Its implementation is provided by your adapter and defaults to `process.env`: | ||
* | ||
* ```js | ||
* import { API_SECRET, getSecret } from "astro:env/server" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removes getSecret from the first snippet so that people do not assume it's the only way to access them (+ it's an advanced uscase)