Rate Limiting with Hooks
Implement request rate limiting in the handle() hook to protect API routes.
Why Rate Limit
Protect APIs from abuse: brute-force logins, scraping, and accidental overload.
Implement in handle
Track requests per IP in memory or Redis and reject when over limit.
const counts = new Map();
export async function handle({ event, resolve }) {
const ip = event.getClientAddress();
const n = (counts.get(ip) || 0) + 1;
counts.set(ip, n);
if (n > 100) return new Response("Too many", { status: 429 });
return resolve(event);
}