Sliding window limiter for Next.js API routes
Production rate limiting with in-memory sliding window (works on Vercel, single Lambda) and optional Upstash Redis for multi-instance production. Per-endpoint configs, X-RateLimit headers, 429 responses with Retry-After, withRateLimit() and withAuthRateLimit() wrappers, and a peek function for dashboard display.
@upstash/ratelimit@upstash/redis1var(--text-3);font-style:italic">// Protect an API route:2export const POST = withRateLimit('auth', async (req) => {3 return NextResponse.json({ ok: true })4})5var(--text-3);font-style:italic">// Automatic 429 + Retry-After on breach. X-RateLimit-* headers on all responses.Short excerpt. Full block includes SQL migrations, error handling, RLS policies, and complete file structure.
One-time Β· Instant GitHub access
βInstant GitHub repo access
βOwn the code forever
βFree updates
β30-day refund if it breaks