hapi-ratelimit-mongoose

1.1.2 • Public • Published

hapi-ratelimit-mongoose npm version

This package is a Hapi.js plugin based on MongoDB that give a global rate limit control on your app/API. You can also set up some specific rate limits on each route config.

Getting started

Go in your project root directory and install with npm:

npm install hapi-ratelimit-mongoose --save

Global rate limit setup

//server.js or app.js ... (anywhere you setup your server)
 
server.register({
    register: require('hapi-ratelimit-mongoose'),
    options: {
        global: {
            limit: 20,
            duration: 5000
        }
    }
}, function(err) {
        console.log(err||'Ratelimit plugin is loaded');
});

Route rate limit setup

//route.js or main.js ... (anywhere you define a route)
 
server.route({
    method: 'GET',
    path: '/',
    config: { 
        plugins: { 
            'hapi-ratelimit-mongoose': {
                limit: 200,
                duration: 5000
            }
       }
    }
});

Todo

  • Setup unit test (so refactor & review some part of the code)
  • Add way to store IP/timestamp, not just mongoDB (JSON for example...). Then, allow to choose the storage system in the options parameter.

/hapi-ratelimit-mongoose/

    Package Sidebar

    Install

    npm i hapi-ratelimit-mongoose

    Weekly Downloads

    8

    Version

    1.1.2

    License

    MIT

    Last publish

    Collaborators

    • laudeon