Skip to content

chore: add skew-version support in Cloudflare open-next worker #7980

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/site/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import { getDeploymentId } from '@opennextjs/cloudflare';
import createNextIntlPlugin from 'next-intl/plugin';

import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs';
Expand Down Expand Up @@ -95,6 +96,16 @@ const nextConfig = {
'shiki',
],
},
// If we're building for the Cloudflare deployment we want to set
// an appropriate deploymentId (needed for skew protection)
// TODO: The `OPEN_NEXT_CLOUDFLARE` environment variable is being
// defined in the worker building script, ideally the open-next
// adapter should set it itself when it invokes the Next.js build
// process, onces it does that remove the manual `OPEN_NEXT_CLOUDFLARE`
// definition in the package.json script.
deploymentId: process.env.OPEN_NEXT_CLOUDFLARE
? getDeploymentId()
: undefined,
};

const withNextIntl = createNextIntlPlugin('./i18n.tsx');
Expand Down
13 changes: 12 additions & 1 deletion apps/site/open-next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import type { OpenNextConfig } from '@opennextjs/cloudflare';
import { defineCloudflareConfig } from '@opennextjs/cloudflare';
import incrementalCache from '@opennextjs/cloudflare/overrides/incremental-cache/kv-incremental-cache';

const cloudflareConfig = defineCloudflareConfig({ incrementalCache });

export default { ...cloudflareConfig, buildCommand: 'pnpm build:default' };
const openNextConfig: OpenNextConfig = {
...cloudflareConfig,
buildCommand: 'pnpm build:default',
cloudflare: {
skewProtection: {
enabled: true,
},
},
};

export default openNextConfig;
6 changes: 3 additions & 3 deletions apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"build:blog-data": "cross-env NODE_NO_WARNINGS=1 node ./scripts/blog-data/generate.mjs",
"build:blog-data:watch": "node --watch --watch-path=pages/en/blog ./scripts/blog-data/generate.mjs",
"build:default": "cross-env NODE_NO_WARNINGS=1 next build",
"cloudflare:build:worker": "opennextjs-cloudflare build",
"cloudflare:deploy": "wrangler deploy",
"cloudflare:build:worker": "OPEN_NEXT_CLOUDFLARE=true opennextjs-cloudflare build",
"cloudflare:deploy": "opennextjs-cloudflare deploy",
"cloudflare:preview": "wrangler dev",
"predeploy": "node --run build:blog-data",
"deploy": "cross-env NEXT_PUBLIC_STATIC_EXPORT=true node --run build:default",
Expand Down Expand Up @@ -79,7 +79,7 @@
"@eslint/eslintrc": "~3.3.1",
"@flarelabs-net/wrangler-build-time-fs-assets-polyfilling": "^0.0.0",
"@next/eslint-plugin-next": "15.3.4",
"@opennextjs/cloudflare": "^1.3.0",
"@opennextjs/cloudflare": "^1.5.1",
"@playwright/test": "^1.53.2",
"@testing-library/user-event": "~14.6.1",
"@types/semver": "~7.7.0",
Expand Down
16 changes: 13 additions & 3 deletions apps/site/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"$schema": "./node_modules/wrangler/config-schema.json",
"main": ".open-next/worker.js",
"name": "nodejs-website",
"compatibility_date": "2024-11-07",
"compatibility_flags": ["nodejs_compat"],
"account_id": "8ed4d03ac99f77561d0e8c9cbcc76cb6",
"account_id": "fb4a2d0f103c6ff38854ac69eb709272",
"minify": true,
"keep_names": false,
"assets": {
"directory": ".open-next/assets",
"binding": "ASSETS",
"run_worker_first": true,
},
"vars": {
// Variables needed for skew protection
// Also note that an appropriate CF_WORKERS_SCRIPTS_API_TOKEN secret
// needs to be set as well in the Cloudflare dashboard
"CF_WORKER_NAME": "nodejs-website",
"CF_PREVIEW_DOMAIN": "nodejsorg.workers.dev",
"CF_ACCOUNT_ID": "fb4a2d0f103c6ff38854ac69eb709272",
},
"observability": {
"enabled": true,
Expand All @@ -25,8 +35,8 @@
},
"kv_namespaces": [
{
"binding": "NEXT_CACHE_WORKERS_KV",
"id": "32e8e26d2d2647fd96789baf83209fa9",
"binding": "NEXT_INC_CACHE_KV",
"id": "69b7422d56dd4244bc0127b69ecdc36f",
},
],
}
2 changes: 1 addition & 1 deletion packages/rehype-shiki/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { shiki, getLanguageDisplayName, highlightToHast, highlightToHtml } =
// `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
// for security reasons.
//
// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environmen
// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environment
// variable for detection instead of current method, which will enable better
// tree-shaking.
// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615
Expand Down
Loading
Loading