0.0.2 • Published 7 years ago

ip-checker v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

ip-checker

Check client ip for koa & express.

Quick Start

  • npm install ip-checker to install ip-checker;
  • express
var express = require('express')
  , app     = express();
app.use(require('ip-checker')({
  default: '*',
  allow: ['127.0.0.1']
}));
app.listen(3000)
  • koa
var app = require('koa')()
app.use(require('ip-checker')({
  default: '*',
  allow: ['127.0.0.1'],
  mode: 'koa'
}))
app.listen(3000)
  • test
curl -H 'x-forwarded-for: 127.0.0.2' -i  http://localhost:3000/
curl -H 'x-forwarded-for: 127.0.0.1' -i  http://localhost:3000/

Config

NameDescriptionDefault value
defaultAction for unknown ip. * for allow all unknown ips, x for block all unknown ips.*
checkerA string or function to check request ip. Return allow string to allow request, block string to block request, empty string to tell ip-checker it's an unknown requestx-forwarded-for
disableDisable ip-checker or not.false
allowA string array that means request is allowed if client ip is in this set.[]
blockA string array that means request is blocked if client ip is in this set.[]
modeexpress or koa mode.express
emitterYou can emit a disable event with a bool value to switch disable value.
process.env.IP_CHECKER_DEBUGSet this value to true to show debug log