Giter VIP home page Giter VIP logo

Comments (5)

nfriedly avatar nfriedly commented on August 27, 2024

Oof, I'm sorry, I didn't think about that.

Here's a couple of options that are both a little dumb, but might be good enough:

  1. Add a custom middleware that runs after express-slow-down and checks req.slowDown:

    app.use(slowDown({
        // ...
    }));
    app.use((req, res, next) => {
        if (request.slowDown.current === request.slowDown.limit + 1) {
            // onLimitReached code here
        }
        next();
    }));

    The gotcha with this approach is that it now fires after the delay, whereas onLimitReached fired before the delay. That might be acceptable for logging purposes, though.

  2. Drop express-slow-down, and instead use express-rate-limit with a custom handler as shown in the docs. However, make the custom handler slow down responses instead of blocking them:

    app.use(rateLimit({
        // ...
        max: 1, // previous delayAfter value here
        handler: (request, response, next, options) => {
            if (request.rateLimit.used === request.rateLimit.limit + 1) {
                // onLimitReached code here
            }
            const delay = (request.used - request.limit) * 1000
            const timerId = setTimeout(next, delay)
            response.on('close', () => clearTimeout(timerId))
        },
    })

    (Basically recreate a simpler version of express-slow-down v2.0.0.)

from express-slow-down.

stephen-willoughby avatar stephen-willoughby commented on August 27, 2024

thanks, made do with a variation based on 1. Found a bug see #46.

from express-slow-down.

Related Issues (17)

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.