Production-Ready Rule
•
worker/**/*.{ts,js}, src/**/*.{ts,js}
Cloudflare Workers & Hono Edge .cursorrules (.mdc)
High-performance .cursorrules and .cursor/rules/*.mdc configuration for Cloudflare Workers and Hono. Optimize edge startup times, D1 database queries, and KV caching.
.cursor/rules/cloudflare-workers.mdc
---
description: Cloudflare Workers, Hono, D1, and Edge runtime engineering standards
globs: worker/**/*.{ts,js}, src/**/*.{ts,js}
alwaysApply: false
---
# Cloudflare Workers & Hono Standards
## Edge Runtime Constraints
- Never rely on persistent in-memory global state between requests.
- Use c.env.DB (D1) or c.env.KV for persistent storage and session management.
- Keep dependencies minimal to ensure sub-10ms worker cold startup times.
## Hono Framework Discipline
- Type your Hono instance with the environment bindings: const app = new Hono<{ Bindings: Env }>().
- Always return typed JSON using c.json({ ... }, 200) and handle errors with app.onError().
- Ensure all asynchronous background tasks use ctx.waitUntil(...) so execution completes reliably.
⭐
Using this rule in your open-source project? Reference in your README:
https://cursor.pacebowl.com/rules/cloudflare-workers
Frequently Asked Questions & Implementation Notes
How does it enforce cold-start performance?
It forbids heavy Node.js built-ins and oversized polyfills, restricting dependencies to edge-native libraries to maintain sub-10ms global cold starts.
How does it optimize Cloudflare D1 queries?
It mandates prepared statements using .bind() to prevent SQL injection and batches multi-row writes with db.batch().