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

Pull 1918post change #1922

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ var settings = require('./models/settings.json');
//--
var limiter = process.env.LIMITER_STRING || settings.limiter;

var fudgeMin = 50; // WATCHPOINT: 60 second poll time in MongoDB
var fudgeSec = 5; // WATCHPOINT: 60 second poll time in MongoDB
// WATCHPOINT: ~60 second poll time in MongoDB
var fudgeMin = 60;
var fudgeSec = 6;

var waitInstallCapMin = isDev ? 1 : 60;
var installCapLimiter = rateLimit({
Expand Down Expand Up @@ -292,28 +293,24 @@ var listCapLimiter = rateLimit({
}
});

var waitListRateSec = isDev ? parseInt(5 / 2) : parseInt(5 / 2);
var waitListRateSec = isDev ? parseInt(4 / 2) : 4;
var listRateLimiter = rateLimit({
store: (isDev ? undefined : undefined),
windowMs: waitListRateSec * 1000, // n seconds for all stores
max: 2, // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
max: 1, // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitListRateSec + fudgeSec);

if (isSameOrigin(aReq.get('Referer')).result) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
suppressNavigation: true,
isCustomView: true,
statusData: {
isListView: true,
retryAfter: waitListRateSec + fudgeSec
}
});
} else {
aRes.status(429).send();
}
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
suppressNavigation: true,
isCustomView: true,
statusData: {
isListView: true,
retryAfter: waitListRateSec + fudgeSec
}
});
},
keyGenerator: function (aReq, aRes, aNext) {
return aReq.ip + aReq._parsedUrl.pathname;
Expand Down