Higher effort takes longer and uses more of your credit.
Components
Creative controls for AI products. Play with them, then copy the React and Tailwind code.
Type @ to attach a file, or / for a command.
Listening
Can you rate limit the invite form?
Add rate limiting to the invite form
fetch() routes POST /invite to handleInvite.
Invites are now limited to 5 an hour per IP, and all 12 tests pass. The first test run failed because I counted the hit after the insert.
Sunlit coral reef
Context window112k / 200k
- System3k
- Tools12k
- MCP24k
- Skills2k
- Memory3k
- Messages68k
git push --force
Where should the limit live?
src/worker.ts runs before every route.
- invite-brief.docx121 KB
- abuse-report.xlsxUploading 20%
- worker-logs.zipUpload failed, remove and try again
The build fails because the Node version changed in the last deploy62% sure. Pinning it to 22.2244% sure should fix it.
How should I rate limit the invite form?
Claude Sonnet 5.5 will add the rate limit to src/lib/invites.ts.
import { error } from "./http";const LIMIT = 5;const WINDOW_MS = 60 * 60 * 1000;/* One row per IP, per hour */export async function checkRateLimit(db: D1Database, ip: string) { const hour = Math.floor(Date.now() / WINDOW_MS); const row = await db .prepare("SELECT hits FROM rate_limits WHERE ip = ? AND hour = ?") .bind(ip, hour) .first<{ hits: number }>(); if ((row?.hits ?? 0) >= LIMIT) { return error(429, "Slow down, try again in an hour"); } await db .prepare("INSERT INTO rate_limits VALUES (?, ?, 1) ON CONFLICT DO UPDATE SET hits = hits + 1") .bind(ip, hour) .run(); return null;}Add rate limiting to invites
- runningRead invite formread0.0s
src/worker.ts, 142 lines
- pendingFind submit handlergrep
handleInvite in src/lib/invites.ts
- pendingAdd rate_limits tableD1
CREATE TABLE rate_limits (ip, hits)
- pendingLimit invites per IPedit
src/lib/invites.ts +24 -3
- pendingRun testsbash
pnpm test, 12 files
- pendingDeploy previewwrangler
Cloudflare Workers, preview env
Step 1 of 6 · 0.0s · 0 calls
Add rate limiting to the invite form
I will count invites per IP in D1 and return a 429 after five in an hour. The change is in src/lib/invites.ts and src/worker.ts.