1.0.8 • Published 7 years ago

koa2-rate-limit v1.0.8

Weekly downloads
134
License
MIT
Repository
github
Last release
7 years ago

koa2-rate-limit

Simple rate limiting for Koa2, supports clustered apps, blacklisting and whitelisting.

Install

npm install koa2-rate-limit

Usage

Import the module:

const rateLimit = require('koa2-rate-limit').rateLimit;

OR:

import {rateLimit} from 'koa2-rate-limit';

Set up an application-wide middleware for rate limiting:

app.use(rateLimit(
{
    routes:
    [
        {method: "POST", path: "/v1/authenticate"}
    ],
    interval: 5 * 60 * 1000,
    max: 10,
    whitelist: [],
    blacklist: []
}))
  • routes {Object[]} The routes to apply rate limiting. method {String|RegExp} A string or regular expression to match for the route method. path {String|RegExp} A string or regular expression to match for the route path.
  • interval {Integer} The default rate limiting window (in milliseconds).
  • max {Integer} The default maximum number of requests before rate limiting is applied.
  • whitelist {String[]} An array of default IP addresses to always allow (you can use CIDR notation).
  • blacklist {String[]} An array of default IP addresses to always deny (you can use CIDR notation).

Note

You can optionally specify interval, max, whitelist and blacklist for each route in routes. If you do this it the values you set against the route will be used instead of the defaults.

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago