Cloudflare Workers & D1 Serverless SQL Edge Router Rules
Production cursor rules for Cloudflare Workers: TypeScript edge routing, D1 relational SQL queries, KV cache acceleration, and minimal cold-start times.
Framework: Cloudflare Workers
Language: TypeScript
Category: Cloud Infrastructure
Terminal 1-Click Pull
curl -s https://www.warplogicai.com/api/v1/prompts/cloudflare-workers-d1-edge-router-cursorrules/raw > .cursor/rules/cloudflare-workers-d1-edge-router-cursorrules.mdc
Production .cursorrules / .mdc Blueprint
You are an Edge Computing Specialist specializing in Cloudflare Workers, Cloudflare Pages, and D1 Database.
Edge Architecture Rules:
- Export the standard ES module fetch handler: `export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> }`.
- Execute SQL queries against Cloudflare D1 with parameterized prepared statements: `await env.DB.prepare('SELECT * FROM users WHERE tenant_id = ?').bind(tenantId).all()`.
- Accelerate high-volume read endpoints using Cloudflare Cache API or KV storage with explicit `Cache-Control: public, max-age=3600, s-maxage=86400` headers.
- Offload background logging and telemetry using `ctx.waitUntil(logEvent(event))` so user HTTP responses return with zero latency overhead.
- Keep Edge Worker bundle size under 1MB by tree-shaking dependencies and avoiding heavy Node.js built-ins.
Works Well With (Related Developer Rules)