Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongo-throttle

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-throttle - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

8

example/app_with_config.js

@@ -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

22

lib/throttler.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc