A fun Cloudflare Workers todo app using all three storage primitives:
- D1 stores todos.
- KV stores app preferences like the selected theme and daily vibe.
- R2 stores optional todo attachments.
Install dependencies:
npm installFor deploy-button users, Cloudflare can provision D1, KV, and R2 automatically from wrangler.toml.
For manual setup, create Cloudflare resources:
wrangler d1 create quest-list-worker-TODO_DB
wrangler kv namespace create TODO_KV
wrangler r2 bucket create quest-list-worker-todo-bucketCopy the generated D1 database ID, KV namespace ID, and R2 bucket name into wrangler.toml if you are not using automatic provisioning.
Create the database tables locally:
npm run db:migrate:localFor production, run the remote migration too:
npm run db:migrate:remoteAdd the admin secret:
wrangler secret put ADMIN_TOKENFor local development, copy .dev.vars.example to .dev.vars and change the token:
ADMIN_TOKEN=pick-a-local-secretRun locally:
npm run devDeploy:
npm run deployGET /serves the app.GET /api/configreturns app config, current theme, daily vibe, and upload limit.GET /api/todoslists todos.POST /api/todoscreates a todo.PATCH /api/todos/:idupdates a todo.DELETE /api/todos/:iddeletes a todo and its R2 attachment.POST /api/todos/:id/attachmentuploads an attachment to R2 with multipart fieldfile.GET /api/todos/:id/attachmentdownloads an attachment from R2.DELETE /api/todos/:id/attachmentremoves an attachment from R2.POST /api/themestores the selected theme in KV.GET /api/admin/statsreturns protected stats when called withAuthorization: Bearer <ADMIN_TOKEN>.