Deploy on git push
After Go live, a push to main builds and publishes. Pick one provider — GitHub
Actions (USE_GITHUB_DEPLOY=true) or Workers Builds — since running both lets an old commit
overwrite a newer deploy.
-
Create the deploy tokens and store them.
Cloudflare dashboard → My Profile → API Tokens → Create Token → Custom.
D1_READ_TOKENgoes in.env.prodinstead ofgh secret; step 2 sends it.Secret Scope CLOUDFLARE_API_TOKENEdit Cloudflare Workers CLOUDFLARE_D1_WRITE_TOKEND1 Edit only D1_READ_TOKEND1 Read only — the only one the build itself gets Terminal gh secret set CLOUDFLARE_API_TOKEN # each reads the value from stdingh secret set CLOUDFLARE_D1_WRITE_TOKEN -
Send the build variables and switch
deploy.ymlon.Terminal pnpm cf:ci --dry-runpnpm cf:ci --enableReads
.env.prod(or.env), sends each build key per its# ci:line, setsUSE_GITHUB_DEPLOY=true; run it again after adding a build key. -
Push to
main.The workflow runs
pnpm check,pnpm testand the build before it deploys.
-
Connect the repository.
Cloudflare dashboard → Workers & Pages → your Worker → Settings → Build → Connect:
Field Value Repository / branch your repository, mainRoot directory holds package.jsonandwrangler.jsonc—/as the starter shipsBuild command pnpm buildDeploy command pnpm exec wrangler deploy— the pinned wrangler, notnpxAPI token leave empty; Cloudflare generates one -
Add the build variables under Variables and secrets on the same page.
PNPM_VERSION=10.12.4,CLOUDFLARE_ACCOUNT_ID,D1_DATABASE_ID, andD1_READ_TOKENas a secret — all three, or the build fails naming what is missing; see Environment and secrets.pnpm cf:cicannot reach this panel, so type a key you add later in here too. -
Push to
main.Other branches get a preview version and never touch production.
Custom domain:
-
Add the domain to your Cloudflare account as a zone.
-
Workers & Pages → your Worker → Settings → Domains & Routes → Add → Custom domain.
pnpm cf:setupdoes this whensite.urlis on a zone the account owns. -
Set
site.urlto that domain and deploy again.
Verify
Section titled “Verify”| Where | You should see | |
|---|---|---|
| Everything at once | pnpm cf:doctor |
every line ok; anything else names the fix |
| The build ran | the Actions run, or Workers Builds → Deployments | a green build, about a minute |
| It read the real database | the build log | [zerodirs-d1] D1 (remote): N approved listings |
| It is live | https://<your domain>/ |
the change you pushed |
Every dynamic URL ends in a slash
Section titled “Every dynamic URL ends in a slash”-
trailingSlash: 'always': a URL without one earns a 301 (GET) or 308 (everything else), which Stripe records as a failed delivery. Register the Stripe webhook, the Deploy Hook URL, the checkout redirect and every admin route with the slash.https://example.com/api/stripe/webhook/ ← correcthttps://example.com/api/stripe/webhook ← 308, recorded as a delivery failure -
An approval in
/admin/publishes nothing unlessproviders.rebuildis set —'github-dispatch'for Actions,'deploy-hook'for a Deploy Hook created on Settings → Build. -
Workers Builds free plan: 3,000 build minutes a month, 20 minutes per build, one concurrent build per account — a second connected project queues builds, approvals included.
-
Rollback: Workers & Pages → your Worker → Deployments → pick the previous one → Rollback. A failed build deploys nothing; the live version keeps serving.
-
site.urlis baked in at build time: canonicals, the sitemap, the RSS feeds, the absolute OG image URLs. Build with someone else’s value and your canonicals point at their domain. -
<name>.workers.devkeeps working and bypasses a zone-level Access policy — turn it off under Domains & Routes if admin routes are behind Cloudflare Access. See Security.