Giter Club home page Giter Club logo

Comments (5)

oshihirii avatar oshihirii commented on August 27, 2024 3

This worked for me in the end:

var apiLimiter = rateLimit({
    windowMs: 5 * 60 * 1000, // 5 minutes
    max: 3,
    headers: false,
    handler: function(req, res) {
        res.status("429").end();
    },
    store: new MongoStore({
        uri: process.env.RATE_LIMIT_MONGO_CONFIG_CONNECTION_STRING,
        collectionName: "expressRateRecords"
    })
});

where connection string is:

mongodb+srv://user-name:[email protected]/expressRateRecords

So basically, username, password and database defined in the connection string and only using the uri and collectionName config parameters.

from rate-limit-mongo.

okv avatar okv commented on August 27, 2024

Hello.
There a lot of questions in this issue and I don't get them all ;)
I hope my answer about collection and collectionName options will be helpful - it describes how to provide connected instance of the collection.
I'm closing the issue, but if you have specific questions feel free to post.

from rate-limit-mongo.

okv avatar okv commented on August 27, 2024

I'm not aware of that possible issue with Cloudflare and 429, 524 http statuses, sorry cannot help with that.

from rate-limit-mongo.

oshihirii avatar oshihirii commented on August 27, 2024

@okv - it ended up being a problem with my code, so I deleted the comment related to the 524 error.

For reference, I was using:

    handler: function(req, res) {
        res.status("429");
    },

And I don't think the request was 'terminating' and cloudflare was returning a 524 error.

So I used the following code and it resolved the issue:

    handler: function(req, res) {
        res.status("429").end(); // <--- just added .end()  
    },

from rate-limit-mongo.

Hemann55 avatar Hemann55 commented on August 27, 2024

This worked for me in the end:

var apiLimiter = rateLimit({
    windowMs: 5 * 60 * 1000, // 5 minutes
    max: 3,
    headers: false,
    handler: function(req, res) {
        res.status("429").end();
    },
    store: new MongoStore({
        uri: process.env.RATE_LIMIT_MONGO_CONFIG_CONNECTION_STRING,
        collectionName: "expressRateRecords"
    })
});

where connection string is:

mongodb+srv://user-name:[email protected]/expressRateRecords

So basically, username, password and database defined in the connection string and only using the uri and collectionName config parameters.

@okv Consider adding a note in the documentation that "If uri includes username and password, then do not included user and password in the config object."

from rate-limit-mongo.

Related Issues (15)

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.