← Back to Blog
development

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:

ProjectAppBranchDomain
yourname-www-prodapps/wwwmainyoursite.com
yourname-www-previewapps/wwwpreviewpreview.yoursite.com
yourname-cmsapps/cmsmaincms.yoursite.com
yourname-dashboardapps/dashboardmaindashboard.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:

  1. Add an Access application for cms.yoursite.com
  2. Add an Access application for dashboard.yoursite.com
  3. Configure your identity provider (GitHub OAuth recommended)
  4. 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 (or apps/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.