Coder Social home page Coder Social logo

Comments (4)

animir avatar animir commented on May 13, 2024 1

@loretoparisi hi
I think what you did is not dirty.

Usually, there are many certain rules for every application and having all the flexibility of this package is worth.

from node-rate-limiter-flexible.

animir avatar animir commented on May 13, 2024

@loretoparisi hi. if you want to filter that, you should modify middleware not consume points for static routes.

from node-rate-limiter-flexible.

loretoparisi avatar loretoparisi commented on May 13, 2024

@animir thank you. I'm not sure how to achieve that, I mean shall I override the rateLimiter.consume(key, points = 1) function?
Having then this

limiterWrapped.consume(req.connection.remoteAddress)
                    .then(() => {
                        next();
                    })

instead of calling next, may I do something else OR shall I override the whole thing?
Thanks a lot.

from node-rate-limiter-flexible.

loretoparisi avatar loretoparisi commented on May 13, 2024

[UPDATE]
I did it quick and dirty like

const rateLimiterMiddleware = (req, res, next) => {
                // var path = url.parse(req.url).pathname;
                if( req.url.match(apiPath) ) { // api path
                    limiterWrapped.consume(req.connection.remoteAddress)
                        .then(() => {
                            next();
                        })
                        .catch(_ => {
                            var errorMessage = APIHelper.createErrorMessage(429, '', '', 'Too Many Requests');
                            res.status(429).send(errorMessage);
                        });
                } else { // skip
                    next();
                }
            };

thank you by the way.

from node-rate-limiter-flexible.

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.