diff --git a/types/express-rate-limit/express-rate-limit-tests.ts b/types/express-rate-limit/express-rate-limit-tests.ts index fab5badeb8..677c46254b 100644 --- a/types/express-rate-limit/express-rate-limit-tests.ts +++ b/types/express-rate-limit/express-rate-limit-tests.ts @@ -11,7 +11,12 @@ const createAccountLimiter = new RateLimit({ delayAfter: 1, // begin slowing down responses after the first request delayMs: 3 * 1000, // slow down subsequent responses by 3 seconds per request max: 5, // start blocking after 5 requests - message: "Too many accounts created from this IP, please try again after an hour" + message: "Too many accounts created from this IP, please try again after an hour", + handler: (req, _, next) => next(new Error(`TooManyRequests: ${req.ip}`)) +}); + +const callbackWithFewerParams = new RateLimit({ + handler: (req, res) => res.status(429).json(`TooManyRequests: ${req.ip}`) }); class SomeStore implements RateLimit.Store { diff --git a/types/express-rate-limit/index.d.ts b/types/express-rate-limit/index.d.ts index 86b8d497b0..5ae2013aef 100644 --- a/types/express-rate-limit/index.d.ts +++ b/types/express-rate-limit/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for express-rate-limit 2.8 +// Type definitions for express-rate-limit 2.9 // Project: https://github.com/nfriedly/express-rate-limit -// Definitions by: Cyril Schumacher +// Definitions by: Cyril Schumacher , makepost // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import express = require("express"); @@ -17,15 +17,15 @@ declare namespace RateLimit { interface Options { delayAfter?: number; delayMs?: number; - handlers?(req?: express.Request, res?: express.Response, next?: express.NextFunction): any; + handler?(req: express.Request, res: express.Response, next: express.NextFunction): any; headers?: boolean; - keyGenerator?(req?: express.Request, res?: express.Response): string; + keyGenerator?(req: express.Request, res: express.Response): string; max?: number; message?: string; - skip?(req?: express.Request, res?: express.Response): boolean; + skip?(req: express.Request, res: express.Response): boolean; statusCode?: number; store?: Store; - onLimitReached?(req?: express.Request, res?: express.Response, optionsUsed?: Options): void; + onLimitReached?(req: express.Request, res: express.Response, optionsUsed: Options): void; windowMs?: number; } }