@libj/ip-filter
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -6,6 +6,7 @@ "use strict"; | ||
var src_1 = require("@libj/http-meta"); | ||
var constants_1 = require("./constants"); | ||
exports.makeIpFilterMiddleware = function (config) { return function (req, res, next) { | ||
var _a = validateConfig(config), whitelist = _a.whitelist, blacklist = _a.blacklist, response = _a.response, ip = defineIp(req, config); | ||
var response = validateConfig(config).response, ip = defineIp(req, config); | ||
if (ip) { | ||
var isAllowed = whitelist ? isIpInRange_1.isIpInRange(ip, whitelist) : !isIpInRange_1.isIpInRange(ip, blacklist); | ||
var isAllowed = isIpAllowed(ip, config); | ||
if (isAllowed) { | ||
@@ -33,2 +34,9 @@ return next(); | ||
} | ||
function isIpAllowed(ip, config) { | ||
var whitelist = config.whitelist, blacklist = config.blacklist; | ||
if (whitelist) { | ||
return whitelist.indexOf(constants_1.WILDCARD_IP) > -1 ? true : isIpInRange_1.isIpInRange(ip, whitelist); | ||
} | ||
return !isIpInRange_1.isIpInRange(ip, blacklist); | ||
} | ||
function validateConfig(config) { | ||
@@ -35,0 +43,0 @@ if (!config.whitelist && !config.blacklist) { |
{ | ||
"dependencies": { | ||
"@libj/http-meta": "0.1.5", | ||
"@libj/logger": "0.0.5", | ||
"@libj/http-meta": "0.1.6", | ||
"@libj/logger": "0.0.6", | ||
"ip-range-check": "^0.2.0" | ||
}, | ||
"name": "@libj/ip-filter", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Ip filter utils (function, middleware)", | ||
@@ -38,3 +38,3 @@ "author": "Sergey Poskachey <seregynp@gmail.com>", | ||
}, | ||
"gitHead": "f3465afd0105f9003e74b9171b25f6181f36e59e" | ||
"gitHead": "9f86083862e66b5d34d2fdb6954bb3d6d7d563e4" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10497
20
121
+ Added@libj/http-meta@0.1.6(transitive)
+ Added@libj/logger@0.0.6(transitive)
- Removed@libj/http-meta@0.1.5(transitive)
- Removed@libj/logger@0.0.5(transitive)
Updated@libj/http-meta@0.1.6
Updated@libj/logger@0.0.6