From 9bab4a3669e4a6aa72cf44c8dedf15c7418d21d3 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Mon, 18 Nov 2024 11:28:45 -0500 Subject: [PATCH] trying to debug rate-limiting on demo site --- app.js | 3 ++- app/utils.js | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index dccb691d9..cf32c8fd7 100755 --- a/app.js +++ b/app.js @@ -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.", }); diff --git a/app/utils.js b/app/utils.js index f2024ca6b..58061c0fb 100644 --- a/app/utils.js +++ b/app/utils.js @@ -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 };