tiny-koa-rate-limiter
v0.1.1
Published
A very small ip based request rate limiter for Koa 1.2
Downloads
1
Maintainers
Readme
tiny-koa-rate-limiter
This is a tiny middleware library for koa 1.x applications to limit ANY requests by ip
Example
const app = require('koa')();
const limiter = require('tiny-koa-rate-limiter');
app.use(function *errorHandler (next) {
try {
yield next;
} catch (e) {
this.status = e.status;
this.body = { code: e.status, message: e.message };
}
});
// Allow 100 requests from the same IP address for every hour.
// An exception will be thrown setting HTTP Status to 429
app.use(limiter({maxRequests: 100, interval: 60*60**1000}));
app.listen(process.env.PORT);
Execute Tests
To run the tests, type:
npm test