Curtain
This library serves as Express middleware designed to make a yes/no decision about whether to admit a request or to determine that a request has exceeed a threshold and should be rejected with a HTTP 429 or other relevant HTTP response.
Usage
(See the /test folder in the project for more examples)
const RateLimiter = ; var rlm = redis: port: 6379 host: '127.0.0.1' db: 0 ; app;
you can also pass in an existing Redis client like so:
const RateLimiter = ; var rlm = redis: client: yourClient ;
Note: This library calls your error handling middleware. When the rate limit is exceeded by the newest request it will call your promixate error handling middleware; this same middleware will also be called if any other types of errors occur. All errors (whether they are Redis errors or rate limit errors) should be handled by you like this:
app;
If you don't use the ip value of req.ip, (which you probably shouldn't) then you need to attach a value to req representing the key to use for that user that is making the request.
That might look like this:
app;