'Execute a custom function when the rate limit is exceeded (rate-limit-mongo)
Package: npm install --save rate-limit-mongo
ROUTE:
routes.get(
"/example",
general, // This is my rate limit
(req, res) => {
return res.status(201).end()
}
)
MIDDLEWARE:
module.exports.general = new RateLimit({
store: new MongoStore({
uri: process.env.MONGODB_CNN + "api-limiter",
expireTimeMs: 15 * 60 * 1000,
errorHandler: console.error.bind(null, 'rate-limit-mongo'),
collectionName: "general",
}),
max: 50,
windowMs: 15 * 60 * 1000,
skipSuccessfulRequests: true
});
Thank you in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
