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.
Initial setup
Section titled “Initial setup”-
Create a D1 database and update
database_idinapps/server/wrangler.jsonc:Terminal window wrangler d1 create sendcrate -
Set the required Worker secrets:
Terminal window wrangler secret put SENDCRATE_SECRETwrangler secret put SENDCRATE_ADMIN_EMAILwrangler secret put SENDCRATE_ADMIN_PASSWORDwrangler secret put SENDCRATE_CONFIG_YAML -
Build and deploy:
Terminal window pnpm run buildpnpm 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 on Workers
Section titled “Outbound email on Workers”Outbound email automatically uses the EMAIL binding of Cloudflare Email Service. Enable sending for the domain in SENDCRATE_EMAIL_FROM:
wrangler email sending enable example.comOnce the binding is present and SENDCRATE_EMAIL_FROM is set, Sendcrate picks up Cloudflare Email automatically with no extra API keys.
Workers Builds & Previews
Section titled “Workers Builds & Previews”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_ENVset to your target environment name inwrangler.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:
wrangler preview base-config secret put SENDCRATE_SECRETWebsite links on a dedicated domain (apps/sites)
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:
Dedicated Sites Worker (recommended)
Section titled “Dedicated Sites Worker (recommended)”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):
-
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. -
Route
<site_host>/*and*.<site_host>/*to the Sites Worker with proxied DNS records. -
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.
Single Worker alternative
Section titled “Single Worker alternative”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).