question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

express middleware filter out localhost api calls

See original GitHub issue

I’m running a Cluster/Worker configuration and I do internal api calls to localhost. Having configured the rate limiter as a express middleware, I get these internal api calls limited too:

const rateLimiterMiddleware = (req, res, next) => {
                rateLimiter.consume(req.connection.remoteAddress)
                    .then(() => {
                        next();
                    })
                    .catch(_ => {
                        var errorMessage = APIHelper.createErrorMessage(429, '', '', 'Too Many Requests');
                        res.status(429).send(errorMessage);
                    });
            };
            self.app.use(rateLimiterMiddleware);

It would be possibile to filter out localhost / 127.0.0.1 IP address so that the middleware would skip these internal api calls?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
animircommented, Dec 8, 2018

@loretoparisi hey

rateLimiterMemory option name is wrong for RLWrapperBlackAndWhite. it should be limiter

const limiterWrapped = new RLWrapperBlackAndWhite({
    limiter: rateLimiterMemory, // !!!
    whiteList: ['127.0.0.1'],
    runActionAnyway: false,
});
1reaction
animircommented, Dec 7, 2018

@loretoparisi hi, config looks right

you’re right, there was a bug with import

I’ve prepared a patch v0.19.6

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to try IP filter from localhost requests - Stack Overflow
I'm developing an IP filter on node.js and Express, I want to try it, but my server is running on localhost, as my...
Read more >
How to implement search and filtering in a REST API with ...
How to implement search and filtering in a REST API with Node.js and Express.js ? · First, we've to initialize a new project...
Read more >
Express middleware: A complete guide - LogRocket Blog
In this guide, you can explore the basics of using Express.js middleware and learn how to add middleware to a simple Express API....
Read more >
Building a REST API with Node and Express - Stack Abuse
REST APIs are the most common form of APIs nowadays. In this article, we'll be building a simple REST API in JavaScript using...
Read more >
How to create a REST API with Express.js in Node.js
Now, start your Express server from the previous sections. Once your application is started, execute curl http://localhost:3000 in another ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found