Skip to content

Commit

Permalink
trying to debug rate-limiting on demo site
Browse files Browse the repository at this point in the history
  • Loading branch information
janoside committed Nov 18, 2024
1 parent 209b2c2 commit 9bab4a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
});
Expand Down
23 changes: 22 additions & 1 deletion app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1671,5 +1691,6 @@ module.exports = {
awaitPromises: awaitPromises,
perfLogNewItem: perfLogNewItem,
perfLog: perfLog,
fileCache: fileCache
fileCache: fileCache,
expressRequestToJson: expressRequestToJson
};

0 comments on commit 9bab4a3

Please sign in to comment.