npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-full-firewall

v2.0.0

Published

egg插件,防止IP或者某些请求过于频繁

Downloads

14

Readme

说明

  • 插件会对ip和理由请求按照配置的规则进行判断,不符合的跳转到ipRedirectUrl | requestRedirectUrl,或者显示ipCode, ipMessage或者requestCode, requestMessage
  • 如果ip和路由功能都开启,则先对IP进行判断,然后对路由请求进行判断,代码: config.coreMiddleware.unshift(MIDDLEWARE_NAME_IP, MIDDLEWARE_NAME_REQUEST);
  • ip和路由如果有设置多个规则,则只要符合其中一个,就会结束判断
    • 规则 1: 60 秒内同一个 ip 访问 30 次,则禁止访问 300 秒
    • 规则 2: 80 秒内同一个 ip 访问 40 次,则禁止访问 400 秒
  • 在您的应用中必须安装egg-redis,配置见下方

版本更新

依赖

lodash, fast-json-stringify, uglify-es

安装

$ npm i egg-full-firewall egg-redis --save

使用

// config/plugin.js
exports.fullFirewall = {
  enable: true,
  package: 'egg-full-firewall',
};

exports.redis = {
  enable: true,
  package: 'egg-redis',
};

配置

本插件配置 (必选)

// {app_root}/config/config.default.js
exports.fullFirewall = {
  // 是否开启日志,日志位于 logs/你的项目名称/egg-web.log
  logEnable: false,
  // 是否检测IP
  useIP: true,
  // IP 检测规则, interval 时间间隔(秒), count 间隔内允许的次数, expire 封禁时间(秒)
  // 未配置 ipRule 则不会进行检测,但 ipDisabled 仍然有效
  ipRule: [
    // 60秒内请求超过3次就会被封禁300秒
    {
      interval: 60,
      count: 3,
      expire: 300,
    },
  ],
  // IP 被禁的时候,跳转的地址,优先级高于 ipCode和ipMessage,eg: '/ip-disabled'
  ipRedirectUrl: null,
  // IP 被禁的时候返回值
  ipCode: 403,
  // IP 被禁的时候返回的内容
  ipMessage: 'IP DISABLED',
  // 指定忽略检测的 IP列表
  // ipIgnore: ['127.0.0.1'],
  ipIgnore: [],
  // 直接封禁的 IP, useIP需要为 true
  ipDisabled: [],
  // IP 检测时忽略的路由, 支持以 * 结尾
  // 本功能主要用于 ipRedirectUrl, requestRedirectUrl
  // 如果这两个页面中需要请求资源,则会在 ip 判断中被阻止,ip 被阻止后会跳转到 ipRedirectUrl,造成死循环
  // 如果想控制这些资源,可以在 requestRule 进行配置
  ipIgnoreRequest: [
    {
      method: 'GET',
      url: '/build/*',
    },
    {
      method: '/favicon.ico',
      url: '/favicon.ico',
    },
  ],

  // 是否检测路由请求
  useRequest: true,
  // 路由请求 检测规则, urls 请求的路由集合, method 方法,interval 时间间隔(秒), count 间隔内允许的次数, expire 封禁时间(秒)
  requestRule: [
    // 示例: 60秒内用 GET 访问 / 或者 /404 3次以上会被封禁300秒
    {
      // 大写
      method: 'GET',
      interval: 60,
      count: 3,
      expire: 300,
      // 本规则应用到的路由
      urls: ['/', '/404'],
    },
  ],
  // 路由请求 被禁的时候,跳转的地址,优先级高于 requestCode 和 requestMessage ,eg: '/request-disabled'
  requestRedirectUrl: null,
  // 路由请求 被禁的时候返回值
  requestCode: 403,
  // 路由请求 被禁的时候返回的内容
  requestMessage: 'REQUEST DISABLED',
  // 忽略指定 IP 的路由请求
  // requestIgnoreIP: ['127.0.0.1'],
  requestIgnoreIP: [],

  // 本中间件使用 egg-redis,如果没有配置redis对应的名称,则默认使用 app.redis
  ipRedisName: null,
  requestName: null,
  // redis 键前缀
  ipRedisPrefix: 'ip:count',
  requestRedisPrefix: 'request:count',
};

egg-redis 配置 1 (二选一)

// 没有指定 ipRedisName 和 requestName, 则直接使用 app.redis
config.redis = {
  client: {
    port: 6379,
    host: '127.0.0.1',
    password: '123456',
    db: 0,
  },
};

egg-redis 配置 2 (二选一)

/**
 * 如果不希望本插件的缓存数据与应用的缓存混在一起,可以指定 ipRedisName 和 requestName
 * 比如指定 ipRedisName 为 firewallIP, requestName 为 firewallRequest
 * 不要忘记在 fullFirewall 配置中填上名称,ipRedisName和requestName默认都为null
 */

config.redis = {
  clients: {
    firewallIP: {
      port: 6379,
      host: '127.0.0.1',
      password: '123456',
      db: 0,
    },
    firewallRequest: {
      port: 6379,
      host: '127.0.0.1',
      password: '123456',
      db: 1,
    },
  },
};

License

MIT