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

Error using connectionOptions #43

Open
Fchen48 opened this issue Feb 16, 2023 · 0 comments
Open

Error using connectionOptions #43

Fchen48 opened this issue Feb 16, 2023 · 0 comments

Comments

@Fchen48
Copy link

Fchen48 commented Feb 16, 2023

As soon as I add some connectionOptions to the mongo store, the application will throw an error:

[ERROR] RangeError: Maximum call stack size exceeded
    at Object.hasOwnProperty (<anonymous>)
    at C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\cmap\connection_pool.js:99:41
    at Array.reduce (<anonymous>)
    at resolveOptions (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\cmap\connection_pool.js:98:53)
    at new ConnectionPool (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\cmap\connection_pool.js:153:20)       
    at new Server (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\core\sdam\server.js:126:19)
    at createAndConnectServer (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\core\sdam\topology.js:866:18)     
    at updateServers (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\core\sdam\topology.js:910:22)
    at NativeTopology.serverUpdateHandler (C:\Users\mfr\Git\app\node_modules\rate-limit-mongo\node_modules\mongodb\lib\core\sdam\topology.js:567:5)
    at Server.emit (node:events:513:28) uncaughtException
const path = require("path");
const os = require("os");
const rateLimit = require("express-rate-limit");
const MongoStore = require("rate-limit-mongo");

const config = require("../config.json");

const mongoUri = "mongodb+srv://" + config.mongodb.host + "/" + process.env.DB + "?authSource=%24external&retryWrites=true&w=majority";

module.exports = (count = 30, time = 60) => rateLimit({
    store: new MongoStore({
        uri: mongoUri,
        collectionName: "rateLimits",
        connectionOptions: {
            ssl: true,
            sslValidate: false,
            sslCert: path.join(os.homedir(), "X509-cert.pem"),
            sslKey: path.join(os.homedir(), "X509-cert.pem"),
            authMechanism: "MONGODB-X509"
        }
    }),
    windowMs: time * 1000,
    max: count
});
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

1 participant