0.0.1 • Published 5 years ago

koa2-throttling v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

koa2-throttling中间件用来限制用户访问频率,防止一些爬虫频繁的抓取数据

一、使用方法

  • 1、安装包

    npm install koa2-throttling
  • 2、使用方式(在中间件中)

    import throttling from 'koa2-throttling';
    
    export default async (ctx, next) => {
      /**
       * ctx, 上下文
       * username, 登录用户
       * loginMaxLength = 5, 登录用户60s中访问次数
       * unknownMaxLength = 3  未登录用户60s中访问次数
       */
      throttling({ ctx, loginMaxLength: 10 });
      await next();
    };