Skip to content

Cloudflare Workers deployment template with two-pass URL auto-injection, secret sync, rollback, and smoke tests.

Notifications You must be signed in to change notification settings

jroth1111/cloudflare_deploy_template

Repository files navigation

Cloudflare Deploy Template

A drop-in template focused on deployment automation and URL auto-injection for Cloudflare Workers. It auto-injects API and web URLs during deploy and supports:

  • Two-pass URL injection (API -> Web -> API)
  • Secret sync with optional auto-generation
  • D1 migrations (optional)
  • Rollback on deploy failure
  • Cron-limit retry

What this template demonstrates

  • A two-worker deployment (API Worker + static web Worker).
  • URL wiring across services (API URL into web build, web URL back into API CORS).
  • A minimal Hono API with CORS enabled for cross-origin calls.
  • Automatic secret upload with safe defaults and optional auto-generation.
  • Pre-deploy checks for missing Cloudflare bindings plus optional migrations.
  • Rollback and cron-limit fallback to avoid partial releases.

What's included

  • scripts/deploy-workers.ts: two-pass deploy script
  • scripts/env.ts: minimal .dev.vars parser
  • deploy.config.ts: deployment config defaults (edit for your repo)
  • wrangler.toml: API Worker config template
  • apps/web/wrangler.jsonc: web Worker assets config
  • apps/server: minimal Worker entrypoint + build script
  • apps/server/src/index.ts: Hono API with CORS enabled
  • apps/web: minimal Vite app + asset Worker
  • packages/db: sample D1 migrations folder
  • .dev.vars.example: example local env
  • docs/DEPLOYMENT.md: deployment workflow
  • scripts/cf-bootstrap.ts: D1/KV bootstrap helper
  • scripts/smoke-test.ts: post-deploy health check
  • scripts/dev-doctor.ts: local env/tooling validation
  • Dev doctor enforces required secrets and URL vars using Zod.

Usage

  1. Copy this folder into your repo.
  2. Update wrangler.toml and apps/web/wrangler.jsonc names/IDs.
  3. Customize deploy.config.ts for your repo paths and env var names.
  4. Fill out .dev.vars (copy from .dev.vars.example).
  5. Install dev deps for typechecking (optional):
bun install
  1. Deploy:
bun scripts/deploy-workers.ts --env production --sync-secrets

Typecheck the scripts:

bun run typecheck

Notes

  • The script expects a Workers API config at wrangler.toml and a web config at apps/web/wrangler.jsonc unless overridden.
  • Replace placeholder IDs in wrangler.toml before production deploy.

About

Cloudflare Workers deployment template with two-pass URL auto-injection, secret sync, rollback, and smoke tests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published