New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@musicode/egg-rate-limiter

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@musicode/egg-rate-limiter

限制接口调用次数

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

egg-rate-limiter

限制接口调用次数

依赖 egg-redis

Install

$ npm i egg-rate-limiter --save

Usage

// {app_root}/config/plugin.js
exports.rateLimiter = {
  enable: true,
  package: '@musicode/egg-rate-limiter',
};

Configuration

// {app_root}/config/config.default.js
exports.middleware = [
  'rateLimiter',
]
exports.rateLimiter = {
  onError: function (ctx, app) {
    // 超过上限时触发
    // 也可不配此回调,默认会返回 429 状态码
  },
  routers: {
    '/a/b': {
      // 举个例子,1 分钟最多调 10 次
      max: 10,
      duration: 60 * 1000
    }
  }
};

app/extend/context 对象需自行扩展一个 getter,如下:

module.exports = {

get rateLimiterId() { return '可以是用户 id、ip 或别的' }

}

License

MIT

Keywords

FAQs

Package last updated on 13 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc