Skip to content

Commit 23b2687

Browse files
chore: add skew-version support in Cloudflare open-next worker (#7980)
* chore: add skew-version support in Cloudflare open-next worker * fix typo * update ids in wrangler.jsonc file * chore: update cloudflare kv binding name * chore: fix incorrect cloudflare:deploy script * add missingle compat_flag * fix incorrect CF_PREVIEW_DOMAIN * bump open-next adapter and wrangler packages * bump form-data * import open-next adapter in next.config.mjs only if necessary
1 parent 230c564 commit 23b2687

File tree

6 files changed

+344
-137
lines changed

6 files changed

+344
-137
lines changed

apps/site/next.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ const nextConfig = {
9595
'shiki',
9696
],
9797
},
98+
// If we're building for the Cloudflare deployment we want to set
99+
// an appropriate deploymentId (needed for skew protection)
100+
// TODO: The `OPEN_NEXT_CLOUDFLARE` environment variable is being
101+
// defined in the worker building script, ideally the open-next
102+
// adapter should set it itself when it invokes the Next.js build
103+
// process, onces it does that remove the manual `OPEN_NEXT_CLOUDFLARE`
104+
// definition in the package.json script.
105+
deploymentId: process.env.OPEN_NEXT_CLOUDFLARE
106+
? (await import('@opennextjs/cloudflare')).getDeploymentId()
107+
: undefined,
98108
};
99109

100110
const withNextIntl = createNextIntlPlugin('./i18n.tsx');

apps/site/open-next.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import type { OpenNextConfig } from '@opennextjs/cloudflare';
12
import { defineCloudflareConfig } from '@opennextjs/cloudflare';
23
import incrementalCache from '@opennextjs/cloudflare/overrides/incremental-cache/kv-incremental-cache';
34

45
const cloudflareConfig = defineCloudflareConfig({ incrementalCache });
56

6-
export default { ...cloudflareConfig, buildCommand: 'pnpm build:default' };
7+
const openNextConfig: OpenNextConfig = {
8+
...cloudflareConfig,
9+
buildCommand: 'pnpm build:default',
10+
cloudflare: {
11+
skewProtection: {
12+
enabled: true,
13+
},
14+
},
15+
};
16+
17+
export default openNextConfig;

apps/site/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build:blog-data": "cross-env NODE_NO_WARNINGS=1 node ./scripts/blog-data/generate.mjs",
88
"build:blog-data:watch": "node --watch --watch-path=pages/en/blog ./scripts/blog-data/generate.mjs",
99
"build:default": "cross-env NODE_NO_WARNINGS=1 next build",
10-
"cloudflare:build:worker": "opennextjs-cloudflare build",
11-
"cloudflare:deploy": "wrangler deploy",
10+
"cloudflare:build:worker": "OPEN_NEXT_CLOUDFLARE=true opennextjs-cloudflare build",
11+
"cloudflare:deploy": "opennextjs-cloudflare deploy",
1212
"cloudflare:preview": "wrangler dev",
1313
"predeploy": "node --run build:blog-data",
1414
"deploy": "cross-env NEXT_PUBLIC_STATIC_EXPORT=true node --run build:default -- --turbo",
@@ -79,7 +79,7 @@
7979
"@eslint/eslintrc": "~3.3.1",
8080
"@flarelabs-net/wrangler-build-time-fs-assets-polyfilling": "^0.0.0",
8181
"@next/eslint-plugin-next": "15.3.4",
82-
"@opennextjs/cloudflare": "^1.3.0",
82+
"@opennextjs/cloudflare": "^1.6.0",
8383
"@playwright/test": "^1.53.2",
8484
"@testing-library/user-event": "~14.6.1",
8585
"@types/semver": "~7.7.0",
@@ -110,7 +110,7 @@
110110
"typescript": "catalog:",
111111
"typescript-eslint": "~8.35.1",
112112
"user-agent-data-types": "0.4.2",
113-
"wrangler": "^4.22.0"
113+
"wrangler": "^4.25.1"
114114
},
115115
"imports": {
116116
"#site/*": [

apps/site/wrangler.jsonc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
{
2+
"$schema": "./node_modules/wrangler/config-schema.json",
23
"main": ".open-next/worker.js",
34
"name": "nodejs-website",
45
"compatibility_date": "2024-11-07",
5-
"compatibility_flags": ["nodejs_compat"],
6-
"account_id": "8ed4d03ac99f77561d0e8c9cbcc76cb6",
6+
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
7+
"account_id": "fb4a2d0f103c6ff38854ac69eb709272",
78
"minify": true,
89
"keep_names": false,
910
"assets": {
1011
"directory": ".open-next/assets",
1112
"binding": "ASSETS",
13+
"run_worker_first": true,
14+
},
15+
"vars": {
16+
// Variables needed for skew protection
17+
// Also note that an appropriate CF_WORKERS_SCRIPTS_API_TOKEN secret
18+
// needs to be set as well in the Cloudflare dashboard
19+
"CF_WORKER_NAME": "nodejs-website",
20+
"CF_PREVIEW_DOMAIN": "nodejsorg",
21+
"CF_ACCOUNT_ID": "fb4a2d0f103c6ff38854ac69eb709272",
1222
},
1323
"observability": {
1424
"enabled": true,
@@ -25,8 +35,8 @@
2535
},
2636
"kv_namespaces": [
2737
{
28-
"binding": "NEXT_CACHE_WORKERS_KV",
29-
"id": "32e8e26d2d2647fd96789baf83209fa9",
38+
"binding": "NEXT_INC_CACHE_KV",
39+
"id": "69b7422d56dd4244bc0127b69ecdc36f",
3040
},
3141
],
3242
}

packages/rehype-shiki/src/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const { shiki, getLanguageDisplayName, highlightToHast, highlightToHtml } =
2626
// `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
2727
// for security reasons.
2828
//
29-
// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environmen
29+
// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environment
3030
// variable for detection instead of current method, which will enable better
3131
// tree-shaking.
3232
// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615

0 commit comments

Comments
 (0)