Coder Social home page Coder Social logo

rate-limiter's Introduction

Rate-limiter

Rate limiter enables IP address based rate limiting for HTTP(s) requests.

HTTP methods supported:
GET
HEAD
POST
PUT
DELETE
ALL - includes all the supported methods mentioned above

Rate limiter allows you to:

  • Add a new limit for a given path and HTTP method:
    var limiter = new RateLimiter();
    limiter.addLimit('/test-path/', 'GET', 2, 500);
    where,
    '/test-path/' is the path
    'GET' is the HTTP method the limit applies to
    2 is the request count allowed per given period
    500 is the time period for the request in seconds

  • Remove Limit:
    limiter.removeLimit('/test-path/', 'GET');
    where,
    '/test-path/' is the path set on a limit
    'GET' is the HTTP method associated with the path

  • Reset IP address access counter for the given IP address:
    limiter.resetIpAddressAccessCounter('/test-path', 'GET', '127.0.0.1');
    where,
    '/test-path/' is the path set on a limit
    'GET' is the HTTP method associated with the path
    '127.0.0.1' is the IP address for which the counter will be reset

  • Process a request and execute callback if the limit is not reached, else drop the request:
    var sampleReq = {'url': '/test-path/', 'method': 'GET', 'socket': {'remoteAddress': '127.0.0.1'}};
    var sampleRes = {'writeHead': writeHead, 'end': end};
    limiter.processRequest(sampleReq, sampleRes, callback);
    where,
    sampleReq is the request object sampleRes is the response object
    callback is called with request and response if the limit is not reached

Build Status:

Build Status

Tests

npm test

Lint

npm run-script lint

rate-limiter's People

Contributors

fhemberger avatar kami avatar lekhajee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rate-limiter's Issues

Can I use flash messages?

Hello,
thanks a lot for this middleware! It's awesome. But i have one little question. Can i use flash messages? I mean i want to change the error message when the limit is reached. Can i do it?
Thanks a lot for the time you shared,
Nikolay Anastasov.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.