hapi-ratelimiter
A simple IP based rate limiting plugin for Hapi using Redis.
##Installation
npm install hapi-ratelimiter
Usage
In the Hapi init code:
const Hapi = require('hapi');
const Limiter = require('hapi-ratelimit');
const server = new Hapi.Server();
server.connection();
const options = {
redis: process.env.REDIS_URL,
namespace: 'clhr',
global: {
limit: 200,
duration: '30 minutes'
}
};
connection.register({ register: Limiter, options: options }, (err) => {
if (err) {
throw err;
}
});
connection.route({
method: 'GET',
path: '/someImportantRoute',
handler: someHandler,
config: {
plugins: {
'hapi-ratelimit': {
limit: 100,
duration: '1 hour'
}
}
}
});
Credits
This module borrows heavily from creativelive/hapi-ratelimit, so credit for original implementation goes there.
The rate-limiting logic in itself relies on tj/node-ratelimiter, which is another awesome project.