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

TypeError: Cannot read properties of undefined (reading 'toString') #40

Closed
drewpereli opened this issue May 12, 2023 · 3 comments
Closed

Comments

@drewpereli
Copy link

I'm getting this error when trying to set up a simple example with express-slowdown and rate-limit-redis. Here's the full example:

import express from 'express';
import RedisStore from 'rate-limit-redis';
import slowDown from 'express-slow-down';
import { createClient } from 'redis';

(async () => {
  const client = createClient();

  await client.connect();

  const app = express();

  const speedLimiter = slowDown({
    windowMs: 30 * 1000,
    delayAfter: 1,
    delayMs: 500,
    store: new RedisStore({
      sendCommand: (...args) => client.sendCommand(args),
    }),
  });

  app.use(speedLimiter);

  app.all('*', (req, res) => {
    res.send('Hello');
  });

  app.listen(3000, () => {
    console.log('Server listening on port 3000');
  });
})();

Versions of relevant packages:

express-slow-down@1.6.0
express@4.18.2
rate-limit-redis@3.0.2
redis@4.6.6

I'm assuming the error is on my end somewhere, but any help would be greatly appreciated. Thanks!

@nfriedly
Copy link
Member

Hey, I'm sorry about this, I think if you switch to rate-limit-redis@2.x it will work.

We upgraded the store interface in express-rate-limit, and rate-limit-redis@3.x is using the new interface (only). We're planning on upgrading express-slow-down to also be able to use the new interface, but no one has been able to get to it yet, so things are a bit messy right now.

nfriedly added a commit that referenced this issue May 15, 2023
@drewpereli
Copy link
Author

No worries, thank you for the response, and for this awesome package!

@nfriedly
Copy link
Member

This is now fixed properly with the release of express-slow-down v2.0.0 - the library was re-written to be a wrapper around express-rate-limit and thus now has full compatibility with express-rate-limit stores.

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

2 participants