Skip to content
Browse documentation
On this page

Cloudflare setup

Create the D1 databases, R2 bucket and KV namespace for your own copy and wire them up.

The IDs in wrangler.jsonc belong to the Emberstack demo. Before you deploy your own copy, create your own resources and point the config at them.

Bindings

Binding

Type

Used for

DB

D1

App data and auth

CMS_DB

D1

EmDash content

MEDIA

R2

EmDash media uploads

SESSION

KV

Sessions for the CMS admin

EMAIL

Email Sending

Transactional email

AI

Workers AI

AI models

ASSETS

Static assets

The built site

Code reads them with import { env } from 'cloudflare:workers'.

Create the resources

  1. Rename the Worker

    Change name in wrangler.jsonc. It's the Worker's name on your account.

  2. Create two D1 databases

    Run bunx wrangler d1 create my-app-db and bunx wrangler d1 create my-app-cms. Put each database_name and database_id into the DB and CMS_DB entries.

  3. Create the R2 bucket

    Run bunx wrangler r2 bucket create my-app-media and set bucket_name on the MEDIA binding.

  4. Create the KV namespace

    Run bunx wrangler kv namespace create SESSION and put its id on the SESSION binding.

  5. Set your domain

    Replace the routes entries with your own domain. It must be a zone on the same account; wrangler creates the DNS record and certificate.

  6. Regenerate the types

    Run bun run cf-typegen so worker-configuration.d.ts matches.

bunx wrangler d1 create my-app-db
bunx wrangler d1 create my-app-cms
bunx wrangler r2 bucket create my-app-media
bunx wrangler kv namespace create SESSION
bun run cf-typegen

Domains

routes uses Workers Custom Domains. workers_dev: true keeps a *.workers.dev URL as a fallback. To move an old domain to a new one, keep the old domain in routes and redirect it in src/worker.ts, which runs before Astro. Static files are served before the Worker runs, so their old URLs keep working.

Email

Onboard your domain for Email Sending with bunx wrangler email sending enable yourdomain.com. See Email.