Skip to content

Commit e42dc6b

Browse files
fixup! Document the new .env support for local development
1 parent 9fca2a4 commit e42dc6b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/content/docs/workers/wrangler/environments.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ env.staging.service ={ binding = "<BINDING_NAME>", service = "worker-a-staging"
112112

113113
</WranglerConfig>
114114

115-
### Secrets
115+
### Secrets for production
116116

117117
You may assign environment-specific [secrets](/workers/configuration/secrets/) by running the command [`wrangler secret put <KEY> -env`](/workers/wrangler/commands/#put). You can also create `dotenv` type files named `.dev.vars.<environment-name>`.
118118

119119
Like other environment variables, secrets are [non-inheritable](/workers/wrangler/configuration/#non-inheritable-keys) and must be defined per environment.
120120

121+
### Secrets in local development
122+
123+
<Render file="secrets-in-dev" />
124+
121125
---
122126

123127
## Examples

src/content/partials/workers/secrets-in-dev.mdx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
{}
33
---
44

5-
Put secrets for use in local development in either a `.dev.vars` file or a `.env` file, in the root of your project.
6-
7-
:::note
8-
Do not add secrets as `vars` in your Worker's Wrangler configuration file.
5+
:::caution
6+
Do not use `vars` to store sensitive information in your Worker's Wrangler configuration file. Use secrets instead.
97
:::
108

11-
Choose to use either `.dev.vars` or `.env` but not both. If you define a `.dev.vars` file, then values in `.env` files will be ignored for local development.
9+
Put secrets for use in local development in either a `.dev.vars` file or a `.env` file, in the root of your project.
1210

13-
:::note
14-
The `.dev.vars` and `.env` files should not committed to git. Add `.dev.vars*` and `.env*` to your project's `.gitignore` file.
11+
:::info
12+
Choose to use either `.dev.vars` or `.env` but not both. If you define a `.dev.vars` file, then values in `.env` files will not be included in the `env` object during local development.
1513
:::
1614

1715
These files should be formatted using the [dotenv](https://hexdocs.pm/dotenvy/dotenv-file-format.html) syntax. For example:
@@ -21,6 +19,10 @@ SECRET_KEY="value"
2119
API_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
2220
```
2321

22+
:::caution [Do not commit secrets to git]
23+
The `.dev.vars` and `.env` files should not committed to git. Add `.dev.vars*` and `.env*` to your project's `.gitignore` file.
24+
:::
25+
2426
To set different secrets for each Cloudflare environment, create files named `.dev.vars.<environment-name>` or `.env.<environment-name>`.
2527

2628
When you select a Cloudflare environment in your local development, the corresponding environment-specific file will be loaded ahead of the generic `.dev.vars` (or `.env`) file.
@@ -34,6 +36,8 @@ When you select a Cloudflare environment in your local development, the correspo
3436

3537
:::note
3638
To disable loading local dev vars from `.env` files without providing a `.dev.vars` file, set the `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV` environment variable to `"false"`.
39+
:::
3740

41+
:::note
3842
To include every environment variable defined in your system's process environment as a local development variable, ensure there is no `.dev.vars` and then set the `CLOUDFLARE_INCLUDE_PROCESS_ENV` environment variable to `"true"`.
3943
:::

0 commit comments

Comments
 (0)