Skip to content

IP filter middleware for ThinkJS 2.0, support whiteList & blackList

License

Notifications You must be signed in to change notification settings

thinkjs/think-ip-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

IP filter middleware for ThinkJS 2.0, support whiteList & blackList

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published