trying to debug rate-limiting on demo site

This commit is contained in:
Dan Janosik 2024-11-18 11:28:45 -05:00
parent 209b2c2f07
commit 9bab4a3669
No known key found for this signature in database
GPG key ID: 70C0B166321C0AF8
2 changed files with 24 additions and 2 deletions

3
app.js
View file

@ -267,7 +267,8 @@ if (rateLimitWindowMinutes == -1) {
return false;
},
handler: function (req, res, next) {
debugErrorLog(`Rate-limiting request: ip=${req.ip}, req=${req.originalUrl}`)
debugErrorLog(`Rate-limiting request: req=${JSON.stringify(utils.expressRequestToJson(req))}`);
res.status(429).json({
message: "Too many requests, please try again later.",
});

View file

@ -1373,6 +1373,26 @@ function bip32Addresses(extPubkey, addressType, account, limit=10, offset=0) {
return addresses;
}
function expressRequestToJson(req) {
return {
method: req.method,
url: req.url,
headers: req.headers,
query: req.query,
params: req.params,
body: req.body,
cookies: req.cookies,
signedCookies: req.signedCookies,
ip: req.ip,
ips: req.ips,
protocol: req.protocol,
secure: req.secure,
originalUrl: req.originalUrl,
hostname: req.hostname,
baseUrl: req.baseUrl,
};
}
function difficultyAdjustmentEstimates(eraStartBlockHeader, currentBlockHeader) {
let difficultyPeriod = parseInt(Math.floor(currentBlockHeader.height / coinConfig.difficultyAdjustmentBlockCount));
let blocksUntilDifficultyAdjustment = ((difficultyPeriod + 1) * coinConfig.difficultyAdjustmentBlockCount) - currentBlockHeader.height;
@ -1671,5 +1691,6 @@ module.exports = {
awaitPromises: awaitPromises,
perfLogNewItem: perfLogNewItem,
perfLog: perfLog,
fileCache: fileCache
fileCache: fileCache,
expressRequestToJson: expressRequestToJson
};