How to ship a Cloudflare Worker API with D1 backing
Quando usar: You want a small JSON API with auth and persistence, deployed to Cloudflare.
Fluxo
-
ScaffoldUse the Cloudflare skill. New Worker with D1 binding, Hono router, routes: GET /todos, POST /todos, DELETE /todos/:id.✓ Copiado→ Worker code + wrangler.toml + schema.sql
-
AuthAdd bearer token auth using a secret in env.✓ Copiado→ Middleware + wrangler secret put instructions
-
Deploywrangler d1 execute + wrangler deploy steps.✓ Copiado→ Live URL after deploy
Resultado: A deployed Worker API with D1 persistence.
Armadilhas
- D1 migrations drift between envs — Use wrangler d1 migrations create + apply; don't ad-hoc exec