Giter VIP home page Giter VIP logo

Comments (6)

jeffersonfelixdev avatar jeffersonfelixdev commented on June 9, 2024 1

I added a custom key generator, so now it's OK.
The problem is the key is shared between different rate limiters, so using different keys solves the problem.

In my particular case, I need a custom rate limit per route, so this is the implementation for that:

import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';

const client = createClient();

client.connect();

export const apiLimiter = rateLimit({
  windowMs: 30 * 1000, // 30 seconds
  max: 100,
  standardHeaders: true,
  legacyHeaders: false,
  keyGenerator: req => `[${req.method}] ${req.path}@${req.ip}`,
  store: new RedisStore({
    sendCommand: (...args: string[]) => client.sendCommand(args),
  }),
});

export const paymentLimiter = rateLimit({
  windowMs: 1000, // 1 second
  max: 1,
  standardHeaders: true,
  legacyHeaders: false,
  keyGenerator: req => `[${req.method}] ${req.path}@${req.ip}`,
  store: new RedisStore({
    sendCommand: (...args: string[]) => client.sendCommand(args),
  }),
});

from express-rate-limit.

gamemaker1 avatar gamemaker1 commented on June 9, 2024

Hi,

You are right, the reset header should show 1 for the last request. Let me try reproducing this issue locally, then debug from there.

Regards

from express-rate-limit.

jeffersonfelixdev avatar jeffersonfelixdev commented on June 9, 2024

I tested with default store, and works fine.

The problem is using Redis, but I need it, because I have a node cluster.

from express-rate-limit.

gamemaker1 avatar gamemaker1 commented on June 9, 2024

Ohkay that's great! I'll add this to the common issues section in the wiki.

from express-rate-limit.

tbell511 avatar tbell511 commented on June 9, 2024

I can confirm this is still a problem. The suggestion of using a custom key fixed the issue for me - thanks for the tip!

from express-rate-limit.

nfriedly avatar nfriedly commented on June 9, 2024

@tbell511 Did you get an error logged to the console about double-counting, or did you find this first?

from express-rate-limit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.