Skip to content

0017. Hosted deployment, environment separation, and publication gating

  • Status: Accepted
  • Date: 2026-11-27
  • Deciders: Owner
  • Related: ADR 0011, ADR 0012, ADR 0013, ADR 0014, ADR 0019

The Worker had only been exercised with local Wrangler and dry-run bundles. The checked-in D1 id was a placeholder and there were no remote D1 or R2 resources, no deployment workflow, and no custom domain. The public documentation site was also not deployed. The application must serve the web app and API same-origin at app.commitmentdesk.com, keep inbox.commitmentdesk.com as a redirect alias, and keep the root domain for public documentation.

Production must not receive traffic from an unapproved change, pull-request CI must remain credential-free, and staging must be isolated from production data.

  • Serve the React web app and /v1 API from one Worker per environment.
  • Use Cloudflare Workers Static Assets for the built web app, with /v1 and /v1/* routed to the Worker first and single-page-application handling for client-side routes.
  • Keep D1 as the relational store and R2 for attachment objects.
  • Serve the public documentation site from a separate Cloudflare Pages project at the root domain. The Worker owns only app.commitmentdesk.com.
Environment Worker D1 R2
Staging commitment-desk-api-staging commitment-desk-staging commitment-desk-attachments-staging
Production commitment-desk-api commitment-desk commitment-desk-attachments

Both hosted environments set ENVIRONMENT=production so session cookies are Secure, HttpOnly, host-only, and SameSite=Lax. WEB_BASE_URL is the environment’s own HTTPS origin. Staging has its own custom domain and credentials; it cannot read production D1 or R2.

  • Use one account-owned Cloudflare API token scoped to the account and commitmentdesk.com, with Workers Scripts, Workers Routes, Workers R2 Storage, D1, Cloudflare Pages, Email Sending, DNS, SSL and Certificates, Zone Settings, Single Redirect, and read/analytics permissions.
  • Store the token in the password manager and in the protected GitHub production environment. Never expose it to pull-request CI, Worker code, logs, or the repository.
  • Deployment is a manual workflow_dispatch workflow on main that requires typing deploy and uses the production environment. Pull requests never deploy.
  • The documentation production workflow is separate and independently gated.

Apply D1 migrations before deploying the Worker. A failed migration stops the deployment before traffic switches. Keep the previous Worker version available and never drop production tables as a rollback shortcut; fix forward when possible.

  • Workers observability is enabled in every environment.
  • A scheduled health workflow checks health, recent Worker errors, webhook failures, and upload growth, and opens an operator issue on sustained failure.
  • Document and rehearse D1 export/Time Travel and R2 versioning or replication before accepting client data.
  • Run the synthetic smoke check after every production deployment. It uses a dedicated synthetic tenant and cleans up its sessions and webhook records.
  • commitmentdesk.com is served by the documentation Pages project.
  • app.commitmentdesk.com is the Worker custom domain.
  • inbox.commitmentdesk.com has a proxied placeholder DNS record and a Single Redirect rule to https://app.commitmentdesk.com, preserving path and query.
  • Deploying the app does not change repository visibility, and the documentation publication gate remains a separate owner decision.
  • One Worker per environment with static assets keeps the app and API same-origin and avoids CORS and cross-subdomain cookie changes.
  • D1 and R2 are account-level resources; the token is therefore broad. Scope the zone and store it as a protected secret, and rotate it on a schedule.
  • Staging uses production cookie settings and email configuration, so synthetic smoke data must never use a real recipient.
  • The deployment workflow lives in .github/**, which the automated bot publish path must not change. Workflow edits require a human-authored pull request.
  • The root documentation site and the application deploy independently. A documentation failure does not block the application, and an application failure does not take down the root site.
  • Serve the SPA from Pages and the API from a separate host: violates the same-origin requirement and changes cookie and CORS behavior.
  • Use Durable Objects as the store: wrong tool for relational data; D1 remains the system of record.
  • One database per tenant: unnecessary operational overhead for the standard tier.
  • Deploy from pull requests: exposes production credentials and bypasses owner approval.
  • Global API key: broader than necessary and not scoped to the account or zone.
  • Attach the application at the root: conflicts with ADR 0011 and the public documentation site.