rate-limit-mongo icon indicating copy to clipboard operation
rate-limit-mongo copied to clipboard

Error using `connectionOptions`

Open Fchen48 opened this issue 2 years ago • 0 comments

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
});

Fchen48 avatar Feb 16 '23 11:02 Fchen48