koa-util-limit
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.7 • Public • Published

koa-util-limit

Install

$ npm install koa-util-limit

Usage

const koaRateLimit = require("koa-util-limit");
const Redis = require("ioredis");
const koa = require("koa");
const app = koa();
app.use(
  koaRateLimit({
    //memory or redis
    driver: "redis",
    //If it is memory, it can be ignored
    db: new Redis(),
    //100 calls at most in 60 * 1000ms
    duration: 60 * 1000,
    max: 100,
    //id unique identification
    id: (ctx) => ctx.ip,
    //whitelist
    white: async (ctx) => {
      //return boolean
    },
    //blacklist
    black: async (ctx) => {
      //return boolean
    },
    //namespace
    namespace: "limit",
    //error response
    error: {
      code: 429,
      msg: "too many requests",
    },
  })
);

Package Sidebar

Install

npm i koa-util-limit

Weekly Downloads

11

Version

1.0.0-beta.7

License

MIT

Unpacked Size

9.01 kB

Total Files

5

Last publish

Collaborators

  • zlgb