Skip to content

Cloudflare (Path B)

This guide covers deploying the LaunchSwift backend (Hono on Cloudflare Workers) to production. You have two options: Wrangler CLI or Alchemy IaC.

  • Cloudflare account
  • Node.js 20+
  • Wrangler CLI (npm install -g wrangler)
  • Authenticated with Cloudflare: wrangler login
Terminal window
wrangler d1 create launchswift-db

Copy the database_id from the output and update backend/wrangler.toml:

[[d1_databases]]
binding = "DB"
database_name = "launchswift-db"
database_id = "your-database-id-here"
Terminal window
wrangler kv namespace create RATE_LIMIT_KV

Copy the id and update backend/wrangler.toml:

[[kv_namespaces]]
binding = "RATE_LIMIT_KV"
id = "your-kv-namespace-id-here"

Apply the database schema:

Terminal window
cd backend
wrangler d1 migrations apply launchswift-db --remote

This creates all schema tables: users, sessions, accounts, verifications, conversations, messages, user_settings, api_usage, and feedback.

Terminal window
cd backend
wrangler secret put BETTER_AUTH_SECRET
wrangler secret put OPENAI_API_KEY # Optional — only if using OpenAI
wrangler secret put ANTHROPIC_API_KEY # Optional — only if using Anthropic
wrangler secret put GEMINI_API_KEY # Optional — only if using Gemini
wrangler secret put APPLE_CLIENT_ID # Optional — for Apple OAuth
wrangler secret put APPLE_CLIENT_SECRET # Optional — for Apple OAuth

Only BETTER_AUTH_SECRET is required. AI provider keys are only needed for the providers you want to support.

In backend/wrangler.toml, update the production environment variables:

[vars]
ENVIRONMENT = "production"
CORS_ORIGIN = "https://your-app-domain.com"
BETTER_AUTH_URL = "https://launchswift-backend.your-account.workers.dev"
Terminal window
cd backend
npm run deploy

This runs the deploy script from backend/package.json (wrangler deploy).

Alchemy provides type-safe infrastructure-as-code deployment:

Terminal window
cd backend
npm run alchemy:deploy

The Alchemy config in backend/alchemy.config.ts defines:

  • D1 database resource
  • KV namespace resource
  • Worker resource and bindings (including env vars + secrets)
  • Observability

In ios/SwiftLaunch/Core/Config/AppConfig.swift, update the production URL used by production(for:):

apiBaseURL: URL(string: "https://launchswift-backend.your-account.workers.dev")!
Terminal window
curl https://launchswift-backend.your-account.workers.dev/healthz

Expected response:

{
"status": "ok",
"environment": "production",
"timestamp": "2026-03-01T12:00:00.000Z"
}

To use a custom domain instead of the .workers.dev URL:

  1. Add a custom domain in the Cloudflare dashboard (Workers & Pages > your worker > Settings > Domains)
  2. Update CORS_ORIGIN and BETTER_AUTH_URL in wrangler.toml
  3. Update apiBaseURL inside AppConfig.production(for:) in the iOS app
  4. Redeploy: npm run deploy

Cloudflare provides built-in observability:

  • Workers Analytics — request count, CPU time, errors
  • D1 Analytics — query count, rows read/written
  • Real-time Logswrangler tail for live log streaming
Terminal window
wrangler tail # Stream live logs from production

”Missing required configuration” (503)

Section titled “”Missing required configuration” (503)”

An AI provider API key is not set. Set it via wrangler secret put.

The user has exceeded the configured limit. Adjust limits in wrangler.toml:

[vars]
RATE_LIMIT_REQUESTS_PER_MINUTE = "120"
RATE_LIMIT_REQUESTS_PER_DAY = "5000"

Migrations haven’t been applied. Run:

Terminal window
wrangler d1 migrations apply launchswift-db --remote

Make sure CORS_ORIGIN in wrangler.toml includes your app’s domain(s). The template defaults to localhost origins for development.