https://github.com/creativelive/hapi-ratelimit
Hapi rate limiting module
https://github.com/creativelive/hapi-ratelimit
Last synced: 8 months ago
JSON representation
Hapi rate limiting module
- Host: GitHub
- URL: https://github.com/creativelive/hapi-ratelimit
- Owner: creativelive
- License: mit
- Created: 2014-01-03T19:20:56.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-08-03T19:15:36.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T07:39:01.159Z (11 months ago)
- Language: JavaScript
- Size: 296 KB
- Stars: 33
- Watchers: 26
- Forks: 15
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-ratelimit
A simple ip based rate limiting plugin for Hapi using Redis.
##Installation
```
npm install hapi-ratelimit
```
## Usage
In the Hapi init code:
```javascript
var Hapi = require('hapi');
var hratelimit = require('hapi-ratelimit');
var server = new Hapi.Server();
// Config for ratelimit
var rateOpts = {
redis:{
port:#redis-port#,
host:#redis-host#
},
namespace: "clhr", //namespace for redis keys
global: {
limit: 200,
duration: 60
} //Set limit to -1 or leave out global to disable global limit
//The global limit is not given priority over local limits
};
var connection = server.connection({
port: 80,
labels: 'something'
});
connection.route({
method: 'GET',
path: '/someImportantRoute',
handler: someHandler,
configs: {
plugins: { // If you want to override the default values
"hapi-ratelimit": {
limit: 100,
duration: 60
} //limits to one hundred hits per minute on a specific route
}
}
});
connection.register({
register: hratelimit,
options: rateOpts
},
function(err) {
console.log(err);
}
);
```