[BLOCKED on upstream] chore(cloudflare): add OpenNext Cloudflare Workers adapter scaffolding - #56
[BLOCKED on upstream] chore(cloudflare): add OpenNext Cloudflare Workers adapter scaffolding#56SaharPak wants to merge 2 commits into
Conversation
Wire up @opennextjs/cloudflare + wrangler so the project can build and
preview via Workers once the upstream adapter supports Next.js 16
proxy.ts (opennextjs-cloudflare#1277 / PR #1280).
What this PR ships:
- package.json (devDependencies): @opennextjs/cloudflare 1.20.1, wrangler 4.x
- package.json scripts:
cf:build -> opennextjs-cloudflare build
preview -> opennextjs-cloudflare build && opennextjs-cloudflare preview
deploy -> opennextjs-cloudflare build && opennextjs-cloudflare deploy
cf-typegen -> wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts
(npm run build / npm run dev / npm run lint / npm run start are
unchanged.)
- wrangler.jsonc at the project root (Workers config; vars for
NEXT_PUBLIC_* only; secrets for SUPABASE_SERVICE_ROLE_KEY +
CRON_SECRET stay out of the file and are set via wrangler secret
put / Cloudflare dashboard).
- open-next.config.ts with a minimal defineCloudflareConfig({})
(no R2 incremental cache, no queues, no image overrides).
- .dev.vars.example as a local-only template (the real .dev.vars
file stays gitignored alongside .env*).
- next.config.ts: call initOpenNextCloudflareForDev() under
process.env.NODE_ENV === 'development' so 'next dev' picks up
Cloudflare bindings locally. npm run build is unaffected.
- .gitignore: ignore .wrangler/ and .dev.vars.
vercel.json is left in place — it is dead config on Cloudflare
Workers (Wrangler ignores it) and there is no strong reason to
remove it in this PR.
Auth logic is untouched. Supabase settings, migrations, and
production secrets are untouched.
… blocker - Correct the target from 'Cloudflare Pages via OpenNext' to 'Cloudflare Workers via OpenNext'. The adapter compiles the Next.js app to a single Worker entry (.open-next/worker.js), not a Pages project. pages_build_output_dir and the Pages concepts are removed; wrangler.jsonc (Workers-style: main, assets binding, services self-reference) is used instead. - Document the deploy blocker: 'npm run cf:build' fails with 'Node.js middleware is not currently supported. Consider switching to Edge Middleware.' because @opennextjs/cloudflare 1.20.1 does not recognize Next.js 16's proxy.ts convention. Upstream issue opennextjs-cloudflare#1277 / PR #1280 is open but not merged. Add a follow-up plan: external HTTP cron service / admin panel / Supabase SQL until a Workers 'scheduled' export can be wired in. - Add NEXT_PUBLIC_SITE_URL to the production env-var table (already in .env.example from the auth PR; this just keeps the docs in sync). - vercel.json is left in place. It is inert on Cloudflare Workers. Removing it is deferred until the deploy is verified end-to-end.
Status: intentionally blocked on upstreamThis PR is not ready to merge as long as What's blocking the deploy
This project uses Upstream status (as of 2026-07-02)
Until #1280 lands and is published, Why I'm shipping this anywayThe config in this PR ( What I deliberately did not do
What to do next
Validation run on this branch
|
Summary
Focused PR that wires up the OpenNext Cloudflare adapter so the project can build, preview, and deploy to Cloudflare Workers once the upstream adapter ships Next.js 16
proxy.tssupport (see "Known blocker" below). No auth logic, no Supabase changes, no production secret changes.What's in this PR
package.json(devDependencies + scripts)@opennextjs/cloudflare@1.20.1andwrangler@4.106.0. Addscf:build,preview,deploy,cf-typegenscripts. Existingdev,build,start,lintare unchanged.wrangler.jsonc(new)main: .open-next/worker.js,assetsbinding,WORKER_SELF_REFERENCEservices self-binding,nodejs_compat. Publicvarsonly — secrets stay out of this file.open-next.config.ts(new)defineCloudflareConfig({})— no R2 incremental cache, no queues, no image overrides. Owner can extend later if those become requirements..dev.vars.example(new)wrangler dev/npm run preview. The real.dev.varsis gitignored.next.config.tsinitOpenNextCloudflareForDev()whenNODE_ENV === "development"sonext devpicks up Cloudflare bindings locally. Gated, sonext buildis unaffected..gitignore.wrangler/and.dev.vars. (.open-next/and.env*were already covered.)README.md,OPERATIONS.mdvercel.jsonis intentionally left in place — it is dead config on Cloudflare Workers (Wrangler ignores it) and removing it is deferred until the deploy is verified end-to-end.Known blocker
npm run cf:buildcurrently fails with:This project uses Next.js 16's
src/proxy.tsconvention (Next 16 renamedmiddleware.ts→proxy.ts). The OpenNext Cloudflare adapter (1.20.1) doesn't yet recognize that convention — it still expectsmiddleware.ts. The fix is upstream:Until that PR lands,
npm run deploywill not produce a deployable Worker. The scaffolding in this PR is ready for the day it does.Cron trigger workaround
Because there is no Workers
scheduledexport wired up, the demo-day cron cannot be triggered bywrangler.toml's[triggers].cronsyet. Today the cron runs via:/api/cron/demo-day)curlwithCRON_SECRETbearer tokenOPERATIONS.md)This is documented in
OPERATIONS.mdandREADME.mdso the owner can pick a path without reading the OpenNext issue tracker.Validation run on this branch
npm run lintnpm run buildnpm run cf:buildBASE_URL=http://localhost:3000 bash ./scripts/auth-smoke.shwrangler devwas not run end-to-end here because no Cloudflare account is connected to this environment — that's a dashboard action for the owner.Owner dashboard actions (after merge, when upstream lands)
productbuilders-app.wrangler.jsoncalready pins the name. Adjustcompatibility_dateif you want a newer runtime date.wrangler vars set <NAME>. Set secrets viawrangler secret put <NAME>(SUPABASE_SERVICE_ROLE_KEY, CRON_SECRET).NEXT_PUBLIC_SITE_URLtohttps://productbuilders.appfor the production env.npm run deploywill work. Re-run the smoke test against the Cloudflare preview URL.scheduledexport and replaces the external HTTP cron with[triggers].cronsinwrangler.jsonc.Risk / assumptions
next.config.tsadds arequire()-based side effect that only fires whenNODE_ENV === "development". This is the recommended OpenNext pattern.next build(CI / production sanity) is unaffected.defineCloudflareConfig({})gives by default. If the owner later wants incremental caching at the edge, that's a separate PR that adds the bucket, the binding, and the R2 incremental cache override.