Skip to content

Worker Deployment

Terminal window
cd worker
wrangler d1 create email-gateway

Copy the returned database_id into wrangler.toml:

[[d1_databases]]
binding = "DB"
database_name = "email-gateway"
database_id = "your-actual-database-id"

Create a worker/.dev.vars file for local development:

AUTH_TOKEN=a-strong-random-token
DESTINATION_EMAIL=your@email.com

This file is gitignored and loaded automatically by Wrangler during wrangler dev.

For production, set secrets via the CLI:

Terminal window
wrangler secret put AUTH_TOKEN
wrangler secret put DESTINATION_EMAIL
Terminal window
# Local D1 (for development)
bun run db:migrate:local
# Remote D1 (production)
bun run db:migrate:remote
Terminal window
bun run deploy

This deploys the worker with:

  • HTTP API (Hono router with bearer auth)
  • Email handler (receives from Cloudflare Email Routing)
  • Durable Object (WebSocket hub for real-time updates)

After deploying, configure the default settings:

Terminal window
curl -X PUT https://email-gateway.your-account.workers.dev/api/settings \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"destination_email": "you@example.com",
"auto_forward_allowed": "true",
"auto_reject_blocked": "true"
}'
Terminal window
bun run dev

This starts a local wrangler dev server with D1 and Durable Objects emulated locally.