Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to update usage of RateLimit itself and its options (delayMs) #21

Open
humoyun opened this issue May 9, 2020 · 0 comments
Open

Comments

@humoyun
Copy link

humoyun commented May 9, 2020

Hi Ben,

I just want to let you know current RateLimit in startServer.ts is obsolete, there is breaking change on express-rate-limit api:

  • v3 changes: Removed delayAfter and delayMs options; they were moved to a new module: express-slow-down.

Also, now RateLimit usage also updated:
Instead of creating RateLimit instance directly, now it should be used as a factory method:

Usage taken from its official npm page:

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100 // limit each IP to 100 requests per windowMs
});

And here is the usage of express-slow-down:

const slowDown = require("express-slow-down");
 
app.enable("trust proxy"); // only if you're behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc)
 
const speedLimiter = slowDown({
  windowMs: 15 * 60 * 1000, // 15 minutes
  delayAfter: 100, // allow 100 requests per 15 minutes, then...
  delayMs: 500 // begin adding 500ms of delay per request above 100:
  // request # 101 is delayed by  500ms
  // request # 102 is delayed by 1000ms
  // request # 103 is delayed by 1500ms
  // etc.
});
 
//  apply to all requests
app.use(speedLimiter);
@humoyun humoyun changed the title Need to update RateLimit options (delayMs) Need to update usage of RateLimit itself and its options (delayMs) May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant