EmDash Guides

Deploying EmDash to Cloudflare Workers

Take your EmDash site from local dev to a globally distributed production deployment on Cloudflare Workers.

EmDash GuidesApril 28, 20262 min read

Why Cloudflare Workers?

EmDash is optimised for Cloudflare Workers — Cloudflare's serverless compute platform that runs your code at the edge, close to your users worldwide. The advantages are significant:

  • Scale to zero — no idle server costs; you pay only for actual CPU time
  • Global distribution — 300+ data centres with near-zero cold starts
  • Dynamic Workers for plugins — each plugin sandbox runs as its own isolated Worker
  • Generous free tier — 100,000 requests per day at no cost

Prerequisites

Step 1 — Authenticate Wrangler

wrangler login

This opens a browser window to authorize Wrangler with your Cloudflare account.

Step 2 — Configure wrangler.toml

In your project root, create or update wrangler.toml:

[main]
name = "my-emdash-site"
main = "dist/server/entry.mjs"
compatibility_date = "2026-01-01"

[vars]
EMDASH_AUTH_SECRET = ""   # Set this in the Cloudflare dashboard

[[d1_databases]]
binding = "DB"
database_name = "my-emdash-db"
database_id = ""   # Fill after creating the D1 database

[[r2_buckets]]
binding = "MEDIA"
bucket_name = "my-emdash-media"

Step 3 — Create a D1 Database

EmDash uses Cloudflare D1 (serverless SQLite) for content storage:

wrangler d1 create my-emdash-db

Copy the database_id from the output and paste it into wrangler.toml.

Step 4 — Create an R2 Bucket

Media uploads are stored in Cloudflare R2:

wrangler r2 bucket create my-emdash-media

Step 5 — Set Environment Variables

Generate a secure auth secret and set it as a Worker secret (never put secrets in wrangler.toml):

npx emdash auth secret
# Copy the output, then:
wrangler secret put EMDASH_AUTH_SECRET

Step 6 — Build and Deploy

npm run build
wrangler deploy

Wrangler bundles your site and uploads it to the Cloudflare edge. Your site is now live at https://my-emdash-site.<your-subdomain>.workers.dev.

Step 7 — Run Database Migrations

Apply EmDash's schema to your new D1 database:

wrangler d1 migrations apply my-emdash-db --remote

Step 8 — Connect a Custom Domain

  1. In the Cloudflare dashboard, go to Workers & Pages → your Worker → Settings → Triggers
  2. Click Add Custom Domain and enter your domain
  3. Cloudflare automatically provisions an SSL certificate and configures DNS

Self-Hosted (Node.js) Alternative

EmDash runs on any Node.js server if you prefer to self-host:

npm run build:node
node dist/server/entry.mjs

Use DATABASE_URL to point at a PostgreSQL or SQLite database and set STORAGE_DRIVER=local for file-based media storage.