-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
chore(meta): add Cloudflare docs #8023
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
dario-piotrowicz
merged 3 commits into
nodejs:main
from
dario-piotrowicz:dario/add-back-cloudflare-docs
Jul 25, 2025
Merged
Changes from 1 commit
Commits
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
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,49 @@ | ||
# Cloudflare Build and Deployment | ||
|
||
The Node.js Website can be built using the [OpenNext Cloudflare adapter](https://opennext.js.org/cloudflare). Such build generates a [Cloudflare Worker](https://www.cloudflare.com/en-gb/developer-platform/products/workers/) that can be deployed on the [Cloudflare](https://www.cloudflare.com) network using [Cloudflare Workers](https://www.cloudflare.com/en-gb/developer-platform/products/workers/). | ||
|
||
## Configurations | ||
|
||
There are two key configuration files related to Cloudflare deployments. | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### Wrangler Configuration | ||
|
||
This file defines the settings for the Cloudflare Worker, which serves the website. | ||
|
||
For more details, refer to the [Wrangler documentation](https://developers.cloudflare.com/workers/wrangler/configuration/). | ||
|
||
Key configurations include: | ||
|
||
- `main`: Points to the worker generated by the OpenNext adapter. | ||
- `account_id`: Specifies the Cloudflare account ID. This is not required for local previews but is necessary for deployments. You can obtain an account ID for free by signing up at [dash.cloudflare.com](https://dash.cloudflare.com/login). | ||
- This is currently set to `fb4a2d0f103c6ff38854ac69eb709272` which is the id of a Cloudflare account, named `nodejs.org`, that the nodejs team is using for testing the Cloudflare deployment. | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- `build`: Defines the build command to generate Node.js filesystem polyfills required for the application to run on Cloudflare Workers. This uses the [`@flarelabs/wrangler-build-time-fs-assets-polyfilling`](https://github.com/flarelabs-net/wrangler-build-time-fs-assets-polyfilling) package. | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- `alias`: Maps aliases for the Node.js filesystem polyfills generated during the build process. | ||
- `kv_namespaces`: Contains a single KV binding definition for `NEXT_INC_CACHE_KV`. This is used to implement the Next.js incremental cache. | ||
- This is currently set up to a KV in the `nodejs.org` Cloudflare testing account. | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### OpenNext Configuration | ||
|
||
This is the configuration for the OpenNext Cloudflare adapter, for more details on such configuration please refer to the [official OpenNext documentation](https://opennext.js.org/cloudflare/get-started#4-add-an-open-nextconfigts-file). | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### Skew Protection | ||
|
||
While Vercel offers [version skew protection](https://vercel.com/docs/skew-protection) out of the box, such mechanism is not present on the platform level in the Cloudflare network and the Open-next adapter provides its own implementation, for more details refer to the [OpenNext official Skew protection documentation](https://opennext.js.org/cloudflare/howtos/skew). | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
The OpenNext skew protection requires the following environment variables to be set in the Wrangler configuration file: | ||
|
||
- `CF_WORKER_NAME` | ||
- The name of the worker (the same as `name`) | ||
- `CF_ACCOUNT_ID` | ||
- The id of the Cloudflare account (this is the same as `account_id`, and again this is set to the Cloudflare testing account used by the nodejs team) | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- `CF_PREVIEW_DOMAIN` | ||
- The preview domain for the worker, given that the preview url for the testing Cloudflare deployments is `https://nodejs-website.nodejsorg.workers.dev/` the domain here is `nodejsorg` | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Additionally upon deployments an extra `CF_WORKERS_SCRIPTS_API_TOKEN` environment variable needs to be set. This variable needs to be set to an API token that has the `Workers Scripts:Read` permission available on the worker's account. | ||
dario-piotrowicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Scripts | ||
|
||
Preview and deployment of the website targeting the Cloudflare network is implemented via the following two commands: | ||
|
||
- `pnpm cloudflare:preview` builds the website using the OpenNext Cloudflare adapter and runs the website locally in a server simulating the Cloudflare hosting (using the [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/)) | ||
- `pnpm cloudflare:deploy` builds the website using the OpenNext Cloudflare adapter and deploys the website to the Cloudflare network (using the [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/)) |
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.
Uh oh!
There was an error while loading. Please reload this page.