mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Merge branch 'master' into production
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user