Skip to content

Cloudflare Workers

Sendcrate runs natively on Cloudflare Workers with Cloudflare D1 for state. The Worker serves the SPA from Workers Static Assets, answers API/RPC/share requests from the same origin, and streams proxied downloads through the Worker.

  1. Create a D1 database and update database_id in apps/server/wrangler.jsonc:

    Terminal window
    wrangler d1 create sendcrate
  2. Set the required Worker secrets:

    Terminal window
    wrangler secret put SENDCRATE_SECRET
    wrangler secret put SENDCRATE_ADMIN_EMAIL
    wrangler secret put SENDCRATE_ADMIN_PASSWORD
    wrangler secret put SENDCRATE_CONFIG_YAML
  3. Build and deploy:

    Terminal window
    pnpm run build
    pnpm run cf:deploy

The Worker never runs database migrations at runtime. pnpm run cf:deploy runs pnpm run cf:migrate first to apply packages/server/migrations/ to the remote D1 database, and pnpm run cf:dev applies them locally.

Outbound email automatically uses the EMAIL binding of Cloudflare Email Service. Enable sending for the domain in SENDCRATE_EMAIL_FROM:

Terminal window
wrangler email sending enable example.com

Once the binding is present and SENDCRATE_EMAIL_FROM is set, Sendcrate picks up Cloudflare Email automatically with no extra API keys.

To deploy continuously with Cloudflare Workers Builds:

  • Root directory: repository root
  • Build command: pnpm run build
  • Deploy command: pnpm run cf:deploy
  • Non-production (preview) command: pnpm run cf:preview
  • Build variable: CLOUDFLARE_ENV set to your target environment name in wrangler.jsonc (for example, production)

cf:preview creates a Worker Preview at https://<branch>-sendcrate.<SENDCRATE_PREVIEW_DOMAIN> backed by the D1 database in the previews block (never production). Set SENDCRATE_PREVIEW_DOMAIN to your account’s workers.dev subdomain, and seed shared preview secrets once:

Terminal window
wrangler preview base-config secret put SENDCRATE_SECRET
Section titled “Website links on a dedicated domain (apps/sites)”

When SENDCRATE_SITE_HOST is configured, each published static site gets its own subdomain (https://<slug>.<site_host>) and any path on it — including /index.html and /assets/* — belongs to the site. Because the app Worker serves its own static assets before invoking the Worker for paths outside run_worker_first, use one of two setups:

Deploy apps/sites as a second Worker that serves only the site host and abuse report form (no app UI, API routes, or scheduled jobs):

  1. Bind the same D1 database and matching configuration as the app Worker: SENDCRATE_SECRET, SENDCRATE_APP_URL, SENDCRATE_SHARE_URL, SENDCRATE_SITE_HOST, SENDCRATE_DEPLOYMENT, email settings, SENDCRATE_ABUSE_EMAIL, and sharing/storage policies.

  2. Route <site_host>/* and *.<site_host>/* to the Sites Worker with proxied DNS records.

  3. Deploy with:

    Terminal window
    pnpm run cf:deploy:sites

In Workers Builds, turn off non-production builds for the Sites Worker and restrict watch paths to apps/sites, apps/server/src/start.ts, apps/server/package.json, packages, plugins, package.json, and pnpm-lock.yaml. Only the app Worker applies migrations, so keep schema changes additive.

Set "run_worker_first": true in apps/server/wrangler.jsonc and route <site_host>/* and *.<site_host>/* to the app Worker as well. Note that every asset request then invokes the Worker (which can add latency when Smart Placement is enabled).