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

express-slow-down

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-slow-down - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

38

lib/express-slow-down.js
"use strict";
const defaults = require("defaults");
const MemoryStore = require("./memory-store");
function SlowDown(options) {
options = defaults(options, {
function SlowDown(opts) {
const options = {
// window, delay, and max apply per-key unless global is set to true

@@ -23,3 +22,4 @@ windowMs: 60 * 1000, // milliseconds - how long to keep records of requests in memory

onLimitReached: function (/*req, res, optionsUsed*/) {},
});
...opts,
};

@@ -29,5 +29,6 @@ // store to use for persisting rate limit data

// ensure that the store has the incr method
// ensure that the store has the increment method
if (
typeof options.store.incr !== "function" ||
(typeof options.store.incr !== "function" &&
typeof options.store.increment !== "function") ||
typeof options.store.resetKey !== "function" ||

@@ -47,7 +48,3 @@ (options.skipFailedRequests &&

options.store.incr(key, function (err, current, resetTime) {
if (err) {
return next(err);
}
const handleIncrement = (current, resetTime) => {
let delay = 0;

@@ -141,3 +138,20 @@

next();
});
};
if (typeof options.store.increment !== "undefined") {
return options.store
.increment(key)
.then(({ totalHits, resetTime }) =>
handleIncrement(totalHits, resetTime)
)
.catch((err) => next(err));
} else {
options.store.incr(key, (err, current, resetTime) => {
if (err) {
next(err);
} else {
handleIncrement(current, resetTime);
}
});
}
}

@@ -144,0 +158,0 @@

{
"name": "express-slow-down",
"version": "1.5.0",
"version": "1.6.0",
"description": "Basic IP rate-limiting middleware for Express that slows down responses rather than blocking the user.",

@@ -34,5 +34,2 @@ "homepage": "https://github.com/nfriedly/express-slow-down",

],
"dependencies": {
"defaults": "^1.0.3"
},
"devDependencies": {

@@ -39,0 +36,0 @@ "body-parser": "^1.20.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