https://github.com/thinkjs/think-ip-filter
IP filter middleware for ThinkJS 2.0, support whiteList & blackList
https://github.com/thinkjs/think-ip-filter
blacklist ip-filter support-whitelist thinkjs
Last synced: 8 months ago
JSON representation
IP filter middleware for ThinkJS 2.0, support whiteList & blackList
- Host: GitHub
- URL: https://github.com/thinkjs/think-ip-filter
- Owner: thinkjs
- License: mit
- Created: 2015-10-31T13:13:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-21T02:10:54.000Z (over 9 years ago)
- Last Synced: 2025-09-22T04:25:59.118Z (9 months ago)
- Topics: blacklist, ip-filter, support-whitelist, thinkjs
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# think-ip-filter
IP filter middleware for **ThinkJS 2.0**, support whiteList & blackList.
## Install
```sh
npm install think-ip-filter --save
```
## How to use
### register middleware
create file if not exist, `src/common/bootstrap/middleware.js`.
```js
import ipFilter from 'think-ip-filter';
think.middleware('ip_filter', ipFilter);
```
### config hook
create file if not exist, `src/common/config/hook.js`.
```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**
```js
export default {
ip_filter: ['111.222.333.444', '121.233.120.11']
}
```
**white list**
```js
export default {
ip_filter: {
whiteList: ['123.222.122.11', '22.33.11.22']
}
}
```
**\* rule**
```js
export default {
ip_filter: {
whiteList: ['123.*.122.11', '*.33.11.22']
}
}
```
**RegExp rule**
```js
export default {
ip_filter: {
whiteList: [/^10\./]
}
}
```
**dynamic load**
dynamic load by function, must be return Promise.
```js
export default {
ip_filter: function(){
//such as: get from db
return Promise.resolve(['111.*']);
}
}
```
## LICENSE
MIT