Coder Social home page Coder Social logo

think-ip-filter's Introduction

think-ip-filter

IP filter middleware for ThinkJS 2.0, support whiteList & blackList.

Install

npm install think-ip-filter --save

How to use

register middleware

create file if not exist, src/common/bootstrap/middleware.js.

import ipFilter from 'think-ip-filter';
think.middleware('ip_filter', ipFilter);

config hook

create file if not exist, src/common/config/hook.js.

export default {
  request_begin: ['prepend', 'ip_filter']
}

config ip whiteList or blackList

add ip_filter config in file src/common/config/config.js.

black list

export default {
  ip_filter: ['111.222.333.444', '121.233.120.11']
}

white list

export default {
  ip_filter: {
    whiteList: ['123.222.122.11', '22.33.11.22']
  }
}

* rule

export default {
  ip_filter: {
    whiteList: ['123.*.122.11', '*.33.11.22']
  }
}

RegExp rule

export default {
  ip_filter: {
    whiteList: [/^10\./]
  }
}

dynamic load

dynamic load by function, must be return Promise.

export default {
  ip_filter: function(){
    //such as: get from db
    return Promise.resolve(['111.*']);
  }
}

LICENSE

MIT

think-ip-filter's People

Contributors

welefen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

think-ip-filter's Issues

如何在特定域下面设置拦截的IP尼?

比如说现在的项目加入了subdomain,那么一个thinkjs项目下面会有多个domain,
admin.A.com
home.A.com
cdn.A.com

现在只有admin.A.com需要加入IP限制,这个该如何配置尼?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.