有没有办法用express-rate-limit和rate-limit-mongo包在我的mongodb数据库中存储用户cookie (jwt)?
我目前正在使用的代码:
var limiter = new RateLimit({
store: new MongoStore({
uri: process.env.MONGO_URI,
expireTimeMs: 60 * 1000 * 60,
}),
max: 150,
windowMs: 10 * 60 * 1000,
message: "Too many requests in a short duration, IP Banned for an hour.",
});我也想知道与请求相关的jwt cookie (如果存在),这样我就可以知道谁是罪魁祸首。
基本上,我如何访问请求对象并将其存储在速率限制数据库中
发布于 2020-09-08 20:06:51
我可以使用express-rate-limit中可用的onLimitReached函数完成此操作,如下所示:
var queslimiter = new RateLimit({
store: new MongoStore({
uri: process.env.MONGO_URI,
expireTimeMs: 60 * 1000 * 60,
collectionName: "ansForce",
}),
max: 30,
message: "Too many requests in a short duration, IP Banned for an hour.",
onLimitReached: async function (req, res) {
try {
const blacklist = new Blacklist({
team: req.cookies.team,
});
try {
const bad = await blacklist.save();
} catch (e) {
console.log(e);
}
} catch (e) {}
},
});https://stackoverflow.com/questions/63782989
复制相似问题