Skip to main content
A binding is a value Cloudflare injects onto env when the Worker runs. better-router exposes that object on the request:
Declare bindings in wrangler.jsonc. Type them by augmenting AppBindings.

Binding map

better-router does not wrap these products. Use the Cloudflare APIs (or your own clients) against getEnv().

D1

wrangler.jsonc
Create the database with npx wrangler d1 create app.

KV

wrangler.jsonc
Create a namespace with npx wrangler kv namespace create KV.

R2

wrangler.jsonc
Create a bucket with npx wrangler r2 bucket create app-media.

Queues

Queues have two sides:
  1. Producerenv.EMAILS.send(body) from a request or cron
  2. Consumer — the Worker queue handler in src/worker.ts
wrangler.jsonc
The consumer is defineWorker({ queue }) — see Worker entrypoint.

Email (inbound)

Email Routing can deliver inbound messages to a Worker. Handle them with defineWorker({ email }).

Cron Triggers

Cron expressions live on the Worker, not in DNS.
wrangler.jsonc
The scheduled event’s cron string is event.cron in defineWorker({ scheduled }). Exporting a handler is not enough — Cloudflare only fires alarms listed in Wrangler.

Assets

The client build is static files. Wrangler serves them in front of the Worker so /assets/client.js does not hit Hono.
Files in public/ are copied by Vite into that directory.

Vars and secrets

Plain values go in vars. Secrets go through wrangler secret put and never sit in git.
Read them with getEnv().STRIPE_SECRET. Locally, put secrets in .dev.vars (Wrangler) or .env (Vite). See Environment.

Type the env

src/env.d.ts
Then getEnv().DB typechecks in loaders, actions, and middleware.

Example wrangler.jsonc

wrangler.jsonc

Other Cloudflare products

These are available on c.env if you bind them: Add them in Wrangler and type them on AppBindings the same way. See examples/cloudflare for D1, a queue producer/consumer, and cron in one app.