Rate limiting
Limit the number of requests in a time window with rateLimit()
import { , } from "@senrijs/senri";
const = ();
.("/api", ({ : 60_000, : 100 })); // 100 per minute- Over the limit, the response is 429 with
Retry-After - It counts in fixed windows
- The default key is the client IP (per /64 for IPv6). Requests with an unknown IP are not limited, and a warning is printed the first time
- Behind a proxy, decide how to get the IP with
trustProxy()
Store
The default store is the process memory.
- With several processes or servers, each counts separately
- On Cloudflare Workers, the limit is per isolate, not global
To count globally, replace store with Redis or the like.
Options
Prop
Type
Prop
Type