From 021598b5c4fa0381f08804b578797969d61bd6c5 Mon Sep 17 00:00:00 2001 From: Leonard Martin Date: Tue, 28 Oct 2014 16:36:37 +0000 Subject: [PATCH] Add README details for custom limit handler --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index b1f5a8f..d223394 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ limiter(options) - `whitelist`: `function(req)` optional param allowing the ability to whitelist. return `boolean`, `true` to whitelist, `false` to passthru to limiter. - `skipHeaders`: `Boolean` whether to skip sending HTTP headers for rate limits () - `ignoreErrors`: `Boolean` whether errors generated from redis should allow the middleware to call next(). Defaults to false. + - `onRateLimited`: `Function` called when a request exceeds the configured rate limit. ### Examples @@ -103,6 +104,16 @@ limiter({ skipHeaders: true }) +// call a custom limit handler +limiter({ + path: '*', + method: 'all', + lookup: 'connection.remoteAddress', + onRateLimited: function (req, res, next) { + next({ message: 'Rate limit exceeded', status: 429 }) + } +}) + ``` ### as direct middleware