5.1.1 • Published 4 years ago
koa-simple-ratelimit v5.1.1
koa-simple-ratelimit
Rate limiter middleware for koa v2. Differs from koa-ratelimit by not depending on ratelimiter and using redis ttl (time to live) to handle expiration time remaining. This creates only one entry in redis instead of the three that node-ratelimiter does.
Installation
npm install koa-simple-ratelimitExample
import Koa from 'koa';
import redis from 'redis';
import { ratelimit } from 'koa-simple-ratelimit';
const app = new Koa();
// Apply rate limit
app.use(ratelimit({
db: redis.createClient(),
duration: 60000,
max: 100
}));
// Response middleware
app.use((ctx, next) => {
ctx.body = 'Stuff!';
return next();
});
app.listen(4000);
console.log('listening on port http://localhost:4000');Options
dbredis connection instancemaxmax requests withinduration2500durationof limit in milliseconds 3600000idid to compare requests ipallowlistarray of ids to allowlistblocklistarray of ids to blocklistprefixredis key prefix "limit"
Responses
Example 200 with header fields:
HTTP/1.1 200 OK
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1384377793
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Date: Wed, 13 Nov 2013 21:22:13 GMT
Connection: keep-alive
Stuff!Example 429 response:
HTTP/1.1 429 Too Many Requests
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1384377716
Content-Type: text/plain; charset=utf-8
Content-Length: 39
Retry-After: 7
Date: Wed, 13 Nov 2013 21:21:48 GMT
Connection: keep-alive
Rate limit exceeded, retry in 8 secondsLicense
MIT
5.1.1
4 years ago
5.1.0
5 years ago
5.0.1
5 years ago
5.0.0
5 years ago
4.0.2
6 years ago
4.0.1
6 years ago
4.0.0
6 years ago
3.1.0
6 years ago
3.0.2
6 years ago
3.0.1
6 years ago
3.0.0
7 years ago
2.4.1
8 years ago
2.4.0
8 years ago
2.3.3
8 years ago
2.3.2
8 years ago
2.3.1
8 years ago
2.3.0
8 years ago
2.2.3
9 years ago
2.2.2
9 years ago
2.2.1
9 years ago
2.2.0
9 years ago
2.1.4
9 years ago
2.1.3
9 years ago
2.1.2
9 years ago
2.1.1
9 years ago
2.1.0
9 years ago
2.0.0
9 years ago
1.2.0
9 years ago
1.1.0
9 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago