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-ip

v1.1.0

Published

egg插件,IP黑白名单

Downloads

9

Readme

说明

  • 插件会对IP进行判断,不符合判断的请求会优先跳转到redirectUrl指向的地址,未设置redirectUrl,则返回响应code, message
  • 插件允许开启白名单或者黑名单,只能开启其中一个
  • 不在白名单或者在黑名单中的都无法通过判断
  • 使用ctx.addIPs(ips: array<string>)批量添加IP名单,参数是字符串数组
  • 使用ctx.addIP(ip: string, expire: number)添加单个IPexpire单位为秒,不填则使用配置中的redisTTL
  • 使用ctx.addIPsExpire(ips: array<string, number>)批量添加IP名单,每个IP都单独设置expire
  • 使用ctx.delIP(ip: string)移除IP名单
  • 插件使用redis来存储数据,因此需要安装egg-redis

版本更新

安装

$ npm install egg-full-ip egg-redis --save

配置

  • 配置egg-full-ip

    // {app_root}/config/config.default.js
    exports.fullIP = {
      // true: 开启白名单,而黑名单会失效
      whiteOnly: false,
      // 当使用内置的判断黑白名单时,需要配置 redis
      redisName: null,
      // redis 键前缀,根据 whiteOnly 会在前缀尾部自行添加 ':w' 和 ':b'
      redisPrefix: 'full:ip',
      // redis IP 缓存时间,单位: 秒, -1 表示永久
      redisTTL: -1,
    
      // 无法通过判断时,跳转地址(优先极高),如 '/403'
      redirectUrl: null,
      // 无法通过判断时,返回值
      code: 403,
      message: 'REQUEST DISABLED',
    };
  • 配置 egg-redis(二选一)

    • 方法一: 没有指定redisName,直接使用app.redis

      // {app_root}/config/config.default.js
      config.redis = {
        client: {
          port: 6379,
          host: '127.0.0.1',
          password: '123456',
          db: 1, // 单独使用一个数据库,方便观察,默认 0
        },
      };
    • 方法二: 指定redisName,例如设置为fullIP

      // {app_root}/config/config.default.js
      config.redis = {
        clients: {
          fullIP: {
            port: 6379,
            host: '127.0.0.1',
            password: '123456',
            db: 1, // 单独使用一个数据库,方便观察,默认 0
          },
        },
      };

使用

  • 配置插件

    // config/plugin.js
    exports.fullIP = {
      enable: true,
      package: 'egg-full-ip',
    };
    
    exports.redis = {
      enable: true,
      package: 'egg-redis',
    };
  • 添加/移除IP,以下函数属于context扩展

    • 批量添加IP: addIPs(ips: array<string>)

      ctx.addIPs(['192.168.1.5', '192.168.1.12']);
    • 批量添加IP且都单独设置expire: addIPsExpire(ips: array<string, number>)expire设置为undefined表示为使用配置中的redisTTL

      ctx.addIPsExpire([
        ['192.168.1.5', 300],
        ['192.168.1.12', -1],
        ['192.168.1.33', undefined],
      ]);
    • 单个添加IP: addIP(ip: string, expire: number)

      ctx.addIP('192.168.1.5', 300);
      ctx.addIP('192.168.1.12');
    • 移除IP: delIP(ip: string)

      ctx.delIP('192.168.1.5');

License

MIT