https://github.com/thinkjs/think-ratelimiter
ThinkJS ratelimit middlewate
https://github.com/thinkjs/think-ratelimiter
Last synced: 9 months ago
JSON representation
ThinkJS ratelimit middlewate
- Host: GitHub
- URL: https://github.com/thinkjs/think-ratelimiter
- Owner: thinkjs
- License: mit
- Created: 2018-01-16T07:13:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-18T23:43:47.000Z (over 8 years ago)
- Last Synced: 2025-02-15T20:52:44.495Z (over 1 year ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 1
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# think-ratelimiter
ThinkJS ratelimit middlewate
## Why use this middleware ?
To protect your applications from Brute Force Request.
## Install
`npm install think-ratelimiter`
## How to use
```js
// in middleware.js
const redis = require('redis');
const { port, host, password } = think.config('redis');
const db = redis.createClient(port, host, { password });
const ratelimiter = require('think-ratelimiter');
module.exports = {
// after router middleware
{
handle: ratelimit,
options: {
db,
errorMessage: 'Sometimes You Just Have To Slow Down',
headers: {
remaining: 'X-RateLimit-Remaining',
reset: 'X-RateLimit-Reset',
total: 'X-RateLimit-Limit'
},
resources: {
'test/test': {
id: ctx => ctx.ip,
max: 5,
duration: 7000 // ms
}
}
}
},
}
```
## Attention
* `X-Ratelimit-Reset` is Unix timestamp (Epoch seconds).
* When users exceed the access limit HTTP response status will be `429 Too Many Request`.