Express middleware for IP-based rate limiting with flexible configuration options and multiple storage backends
Overall
score
96%
Design an Express middleware factory that limits requests per client while grouping IPv6 traffic by subnet when desired. The middleware should rely on the provided rate-limiting dependency to derive IP-based keys, expose the computed key to downstream handlers, and allow toggling between masked IPv6 keys and exact addresses.
limit: 1, windowMs: 60000, and default IPv6 subnet masking, two requests coming from 2001:db8:1:2::10 and 2001:db8:1:2::99 share the same quota, so the first request succeeds and the second receives a 429 response because they map to the same masked key. @testlimit: 1, windowMs: 60000, and IPv6 subnet masking disabled, requests from 2001:db8:1:2::10 and 2001:db8:1:2::99 are treated as separate clients so both requests succeed without tripping the limit. @test203.0.113.10 and 203.0.113.44 always produce separate keys; with limit: 1, each IP can make one request without affecting the other. @testrateLimitKey) before the route handler runs; a handler that echoes this property returns the masked IPv6 key when subnetting is enabled and the exact address when it is disabled. @test@generates
import { RequestHandler } from "express";
export interface RateLimiterOptions {
windowMs?: number;
limit?: number;
ipv6Subnet?: number | false; // defaults to masked IPv6 keys using the dependency's default subnet when omitted
requestPropertyName?: string; // defaults to "rateLimitKey"
}
export function buildRateLimiter(options?: RateLimiterOptions): RequestHandler;Provides rate-limiting middleware with IPv6-aware IP key generation. @satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-express-rate-limitevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10