mirror of
https://github.com/scratchfoundation/node-redis-rate-limiter.git
synced 2024-11-24 16:27:51 -05:00
README about the middleware and individual routes
This commit is contained in:
parent
8d92f4df7e
commit
a9f3edd8c3
1 changed files with 21 additions and 0 deletions
21
README.md
21
README.md
|
@ -156,3 +156,24 @@ server.use(middleware);
|
||||||
|
|
||||||
It rejects any rate-limited requests with a status code of `HTTP 429`,
|
It rejects any rate-limited requests with a status code of `HTTP 429`,
|
||||||
and an empty body.
|
and an empty body.
|
||||||
|
|
||||||
|
*Note:* if you want to rate limit several routes individually, don't forget to use the route name as part of the `key`, for example using Restify:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function ipAndRoute(req) {
|
||||||
|
return req.connection.remoteAddress + ':' + req.route.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
server.get(
|
||||||
|
{name: 'routeA', path: '/a'},
|
||||||
|
rateLimiter.middleware({redis: client, key: ipAndRoute, rate: '10/minute'}),
|
||||||
|
controllerA
|
||||||
|
);
|
||||||
|
|
||||||
|
server.get(
|
||||||
|
{name: 'routeB', path: '/b'},
|
||||||
|
rateLimiter.middleware({redis: client, key: ipAndRoute, rate: '20/minute'}),
|
||||||
|
controllerB
|
||||||
|
);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue