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