mongo-throttle
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -6,4 +6,10 @@ var express = require('express') | ||
var throttlerOptions = { | ||
rateLimit: {max: 10}, | ||
mongoose: {uri: 'mongodb://localhost/mongothrottle'}, | ||
useCustomHeader: 'x-custom-header' | ||
} | ||
var throttler = require('../lib/throttler') | ||
app.use(throttler({rateLimit: {max: 10}, mongoose: {uri: 'mongodb://localhost/mongothrottle'}})) | ||
app.use(throttler(throttlerOptions)) | ||
@@ -10,0 +16,0 @@ // REMOVE PRIOR DOCUMENTS |
@@ -76,12 +76,18 @@ 'use strict' | ||
function throttleMiddleware (request, response, next) { | ||
var ip = request.headers['x-forwarded-for'] || | ||
request.connection.remoteAddress || | ||
request.socket.remoteAddress || | ||
request.connection.socket.remoteAddress || '' | ||
var ip = null | ||
ip = ip.split(',')[0] | ||
if (!ipRegex().test(ip) || ip.substr(0, 7) === '::ffff:' || ip === '::1') { | ||
ip = '127.0.0.1' | ||
if (config.useCustomHeader && request.headers[config.useCustomHeader]) { | ||
ip = request.headers[config.useCustomHeader] | ||
} else { | ||
ip = ip.match(ipRegex())[0] | ||
ip = request.headers['x-forwarded-for'] || | ||
request.connection.remoteAddress || | ||
request.socket.remoteAddress || | ||
request.connection.socket.remoteAddress || '' | ||
ip = ip.split(',')[0] | ||
if (!ipRegex().test(ip) || ip.substr(0, 7) === '::ffff:' || ip === '::1') { | ||
ip = '127.0.0.1' | ||
} else { | ||
ip = ip.match(ipRegex())[0] | ||
} | ||
} | ||
@@ -88,0 +94,0 @@ |
{ | ||
"name": "mongo-throttle", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Basic IP rate-limiting middleware for Express stored in mongoDB. Use to throttle or limit incoming request rate.", | ||
@@ -5,0 +5,0 @@ "main": "lib/throttler.js", |
@@ -53,4 +53,5 @@ # Mongo Throttle | ||
"mongoose":{ | ||
"uri": false // Optional Mongo URI connection string | ||
} | ||
"uri": false // Optional Mongo URI connection string | ||
}, | ||
"useCustomHeader": "x-custom-header" // Count hits by the distinct values found in this header, instead of by IP | ||
} | ||
@@ -57,0 +58,0 @@ |
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
16817
196
109
11