deploy-cloudflare
Skill2 starsChanged 35 days agoMITView on GitHub
Move an app-foundation (Next.js) site from Vercel Hobby to Cloudflare Workers, whose free plan doesn't forbid commercial use, so the site can take payments. Sets up OpenNext, GitHub auto-deploys, Hyperdrive for fast database connections, and fixes the Workers-only bugs. Use when the user says "I want to charge money", "Vercel free plan doesn't allow commercial use", "deploy to Cloudflare", "move off Vercel", or before pay-checkout on a Hobby project.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- FooJiaYin/dev-skillstheir own version, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- FooJiaYin/dev-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/app-foundation/template/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- skills/app-foundation/template/CLAUDE.mdCLAUDE.md
- app-foundationSkill
- auth-loginSkill
- db-backupSkill
- db-connectSkill
- domain-setupSkill
- email-sendSkill
- env-secretsSkill
- file-uploadSkill
- github-vercel-deploySkill
- launch-kitSkill
- ops-dashboardSkill
- pay-checkoutSkill
- pay-subscriptionSkill
- pay-webhookSkill
- uptime-alertSkill
- warehouse-siteSkill
The file
Files
deploy-cloudflare
Goal: the same code runs on Cloudflare Workers (and keeps working on Vercel), deployed automatically from GitHub on every push. Follow ../../STACK.md.
Why
- Vercel Hobby is "restricted to non-commercial personal use only"; "any method of requesting or processing payment" counts as commercial (https://vercel.com/docs/limits/fair-use-guidelines). Charging on Vercel means Pro ($20/month per member).
- Cloudflare Workers Free has no such restriction: 100,000 requests a day, then errors until midnight UTC (never a bill). Workers Paid is $5/month.
- CPU, honestly: Free is documented as 10 ms CPU per request. Our Next.js demo used ~66 ms median (P90 ~330 ms) and Cloudflare cut 0 requests in testing. That's not guaranteed: if visitors start seeing error 1102 / "Exceeded CPU", move to Workers Paid ($5). Say this to the owner; don't promise "free forever".
Rules
- Creating the Cloudflare account, the GitHub authorization and any verification are the owner's clicks. Never sign in or tick a CAPTCHA for them.
- Secrets (
DATABASE_URL,RESEND_API_KEY,BETTER_AUTH_SECRET,BLOB_READ_WRITE_TOKEN,GOOGLE_CLIENT_SECRET, the Hyperdrive connection string) are pasted by the owner, from where they were created, straight into Cloudflare. Never read, copy or type them. Values marked Sensitive in Vercel can't be read back: create new ones (Resend key, BETTER_AUTH_SECRET via /login, Google client secret). - Recommend the Secret type for secrets. If the owner keeps them as plain text, never copy them into
wrangler.jsonceven though Cloudflare's banner suggests it: that file is committed. - Non-secret values (site URL, site name, email sender) the agent may type, with the owner's OK.
Steps
1. Patch the project
node <skill-dir>/scripts/apply.mjs --dir "<project>" --jsonIt adds wrangler.jsonc (with keep_vars: true so dashboard variables survive deploys), open-next.config.ts, public/_headers, the @opennextjs/cloudflare + wrangler packages and cf:* scripts, and .open-next/ to .gitignore. It also fixes the three things that break on Workers:
| Problem on Workers | Symptom | Fix applied |
Next.js bundles the Node build of postgres | CONNECT_TIMEOUT to the database | serverExternalPackages: ["postgres"] in next.config |
| One database client reused across requests | 2nd request fails | src/db/index.ts creates a client per request on Workers (one shared pool elsewhere) |
| One Better Auth instance (holding a DB client) reused | "Failed to get session", server error after login | getAuth() per request on Workers |
result.variables lists every variable name from .env.example and whether it's a secret. Push.
2. Owner: create the Worker from GitHub
Cloudflare → Workers & Pages → Create → Connect GitHub (owner authorizes; suggest "Only select repositories") → pick the repo →
- Project name:
result.worker(must matchnameinwrangler.jsonc) - Build command:
npx opennextjs-cloudflare build - Deploy command:
npx opennextjs-cloudflare deploy - Preview builds: off (optional)
→ Deploy. The site appears at
https://<worker>.<account>.workers.dev. The first build works without variables.
3. Variables
Worker → Settings → Variables and Secrets → Add variable. Agent types the plain ones (NEXT_PUBLIC_SITE_URL = the workers.dev or custom URL, NEXT_PUBLIC_SITE_NAME, EMAIL_FROM); the owner pastes the secrets. Each save redeploys.
Also a build variable: Worker → Settings → Builds → Variables and secrets → owner adds DATABASE_URL (Secret). The build runs scripts/db-migrate.mjs before deploying; without the variable it skips, so new tables are never created once Cloudflare is the only host (found 2026-10-25: a project that had moved off Vercel kept building fine but stopped migrating). Runtime variables are not visible to the build.
Google sign-in: add https://<new-domain>/api/auth/callback/google to the OAuth client's redirect URIs and set GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET.
4. Hyperdrive (strongly recommended, free)
Without it every request opens a new TCP+TLS connection to the database (~550 ms per query in our test). With it: ~70 ms.
Owner: Storage & databases → Hyperdrive → Connect database → public database → paste the direct (unpooled) connection string (DATABASE_URL_UNPOOLED for Neon) → turn caching off (cached reads could keep a signed-out session alive for up to 60 s) → Create. The config ID is not a secret:
node <skill-dir>/scripts/apply.mjs --dir "<project>" --hyperdrive <32-char-id>This adds the binding (with a placeholder localConnectionString, which opennextjs-cloudflare deploy requires). Push.
5. Verify
/api/health→"database":{"status":"connected"}, several times in a row (latency < 150 ms with Hyperdrive)/status→ runtime "Cloudflare"/db-test→ save a row, reload, still there/login→ email code arrives,/accountworks, reload/accounttwice/files(if file-upload ≥ 1.0.1) → upload and delete- Worker → Metrics → "Exceeded CPU Time Limits" stays 0
6. Go live (when ready to charge)
Add the custom domain under Worker → Domains (the domain's DNS must be on Cloudflare: see ../launch-kit/references/cloudflare-domain.md for moving it, including the Resend DKIM record Cloudflare's scan misses, and deleting the old CNAME that blocks "Add domain"), update NEXT_PUBLIC_SITE_URL, Creem's webhook URL, the catch-up workflow's SITE_URL and the Google redirect URI, add the DATABASE_URL build variable (step 3), then disconnect the project from Vercel so production runs only on Cloudflare. Ask before each of these.
Troubleshooting
See references/troubleshooting.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

