Merge branch 'master' into production

This commit is contained in:
Chris Troutner
2022-03-28 23:59:58 +02:00
2 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ const logReqInfo = function (req, res, next) {
body: req.body body: req.body
} }
wlogger.verbose(`Request: ${ip} ${method} ${url}`, dataToLog) wlogger.info(`Request: ${ip} ${method} ${url}`, dataToLog)
next() next()
} catch (err) { } catch (err) {
+18 -2
View File
@@ -1,6 +1,4 @@
/* /*
This file will replace the original rate-limit.js file.
Sets the rate limits for the anonymous and paid tiers. Current rate limits: Sets the rate limits for the anonymous and paid tiers. Current rate limits:
- 10000 points in 60 seconds - 10000 points in 60 seconds
- 500 points per call for anonymous tier (20 RPM) - 500 points per call for anonymous tier (20 RPM)
@@ -258,6 +256,15 @@ class RateLimits {
// const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume) // const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume)
// console.log(`rateLimitData: `, rateLimitData) // console.log(`rateLimitData: `, rateLimitData)
// Add data to logs for analytics.
const logData = {
ip: req.ip,
key,
pointsToConsume,
status: 'OK'
}
wlogger.info(logData)
res.locals.pointsToConsume = pointsToConsume // Feedback for tests. res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
// Signal that the user has not exceeded their rate limits. // Signal that the user has not exceeded their rate limits.
@@ -274,6 +281,15 @@ class RateLimits {
// `rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}` // `rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}`
// ) // )
// Add data to logs for analytics.
const logData = {
ip: req.ip,
key,
pointsToConsume,
status: 429
}
wlogger.info(logData)
// Rate limited was triggered // Rate limited was triggered
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330 res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
return res.json({ return res.json({