Deploying to Cloudflare
This guide walks through deploying all three applications to Cloudflare Pages. By the end, your site will be live at zero monthly cost.
Overview
You'll create four Cloudflare Pages projects:
| Project | App | Branch | Domain |
|---|---|---|---|
yourname-www-prod | apps/www | main | yoursite.com |
yourname-www-preview | apps/www | preview | preview.yoursite.com |
yourname-cms | apps/cms | main | cms.yoursite.com |
yourname-dashboard | apps/dashboard | main | dashboard.yoursite.com |
Step 1: Create D1 Database
wrangler d1 create submissions-db
Copy the database_id into all three wrangler.jsonc files.
Step 2: Create SESSION KV Namespace
wrangler kv namespace create SESSION
Add the id to wrangler.jsonc in all apps.
Step 3: Configure Zero Trust
In the Cloudflare Zero Trust dashboard:
- Add an Access application for
cms.yoursite.com - Add an Access application for
dashboard.yoursite.com - Configure your identity provider (GitHub OAuth recommended)
- Set policies to allow your team's email addresses
Step 4: Set Secrets
wrangler pages secret put GITHUB_PUBLISH_TOKEN --project-name yourname-cms wrangler pages secret put KEYSTATIC_GITHUB_CLIENT_SECRET --project-name yourname-cms wrangler pages secret put KEYSTATIC_SECRET --project-name yourname-cms wrangler pages secret put TURNSTILE_SECRET_KEY --project-name yourname-www-prod wrangler pages secret put RESEND_API_KEY --project-name yourname-www-prod
Step 5: Connect Git Repository
In the Cloudflare Pages dashboard, connect each project to your GitHub repository. Set the build configuration:
- Build command:
bun install && bun run build - Build output directory:
dist - Root directory:
apps/www(orapps/cms,apps/dashboard)
Step 6: Run Migrations
wrangler d1 execute submissions-db --file=./apps/dashboard/migrations/0001_init.sql
Step 7: Configure Custom Domains
Add your custom domains in each Pages project and update DNS records.
Done
Your site is live. Content editors can access cms.yoursite.com, and form submissions appear in dashboard.yoursite.com. All at zero running cost.