-
Notifications
You must be signed in to change notification settings - Fork 46
[cloudflare] add howto env vars #93
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
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c0a588
[cloudflare] add howto env vars
vicb f1f117b
Update pages/cloudflare/howtos/env-vars.mdx
vicb 54fb227
Update pages/cloudflare/howtos/env-vars.mdx
vicb cb82510
Update pages/cloudflare/howtos/env-vars.mdx
vicb dbbe658
Update pages/cloudflare/howtos/env-vars.mdx
vicb 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "NextAuth": "NextAuth", | ||
| "stripeAPI": "Stripe API", | ||
| "dev": "Development workflow" | ||
| "dev": "Development workflow", | ||
| "env-vars": "Enviroment Variables" | ||
| } |
This file contains hidden or 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,35 @@ | ||
| ## Environment variables | ||
|
|
||
| This entry describe the most sensible way to handle your environment variables which works well both during local development and once your application is deployed to Cloudflare Workers. | ||
|
|
||
| On the Cloudflare platform, your environment variables can be stored in either ["Enviroment variables"](https://developers.cloudflare.com/workers/configuration/environment-variables/) or ["Secrets"](https://developers.cloudflare.com/workers/configuration/secrets/). The difference being that Secrets are write only and can not be read back from either the dashboard or the CLI. | ||
|
|
||
| ### Local development | ||
|
|
||
| While there are multiple ways to set environment variables for local development on the Cloudflare platform (adding them to to your [wrangler configuration](https://developers.cloudflare.com/workers/configuration/secrets/) or to a [.dev.vars](https://developers.cloudflare.com/workers/configuration/secrets/) file) that does not play well with the recommended development workflow as they would not be available while using `next dev`. | ||
|
|
||
| What you should do instead is to use the Next.js [`.env` files](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables) instead. By doing so the environment variables will be available on `process.env` both while running `next dev` and when running you app locally on a Worker with `wrangler dev`. | ||
vicb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Next.js `.env` files are environment specific. That is a `.env.development` will take precedence over a `.env` file when you use the "development" environment. See the Next.js site for a detailed explanation of the [loading order](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables). | ||
|
|
||
| You should use the `NEXTJS_ENV` environment variable to select the environment to use when running your app locally on a worker, that's how you would select the "development" environment: | ||
|
|
||
| ```plain | ||
| # .dev.vars | ||
| NEXTJS_ENV=development | ||
| ``` | ||
|
|
||
| The "production" environment is used by default when `NEXTJS_ENV` is not explicitely set. | ||
vicb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Production | ||
|
|
||
| `.env` and `dev.vars` are local files that should not be added to source control. You should instead use the cloudflare dashboard to set you environment variables for production. | ||
vicb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Next.js has [2 kinds](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser) of environment variables: | ||
|
|
||
| - non-`NEXT_PUBLIC_` variables which are only available on the server | ||
| - `NEXT_PUBLIC_` variables on the other hand are available to the browser | ||
|
|
||
| Those are called runtime environment variables (non-`NEXT_PUBLIC_`) and buildtime environment variables (`NEXT_PUBLIC_`) on the Cloudflare paltform. | ||
|
|
||
| You can set the runtime environment variables (non-`NEXT_PUBLIC_`) by following those [instructions](https://developers.cloudflare.com/workers/configuration/environment-variables/#add-environment-variables-via-the-dashboard). The build time environment variables (`NEXT_PUBLIC_`) should be set in the [Builds Configuration](https://developers.cloudflare.com/workers/ci-cd/builds/configuration/) so that their value can be inlined by the Workers Builds. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.