mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 17:22:04 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab198b958e | ||
|
|
2618008247 |
@@ -220,11 +220,16 @@ class RateLimits {
|
|||||||
// it will return the 'res' object with an error status and message, which
|
// it will return the 'res' object with an error status and message, which
|
||||||
// should be returned by the middleware.
|
// should be returned by the middleware.
|
||||||
async trackRateLimits (req, res, jwtToken) {
|
async trackRateLimits (req, res, jwtToken) {
|
||||||
|
const debugInfo = {
|
||||||
|
jwtToken
|
||||||
|
}
|
||||||
|
|
||||||
// Anonymous rate limits are used by default.
|
// Anonymous rate limits are used by default.
|
||||||
let pointsToConsume = ANON_LIMITS
|
let pointsToConsume = ANON_LIMITS
|
||||||
// console.log('pointsToConsume: ', pointsToConsume)
|
// console.log('pointsToConsume: ', pointsToConsume)
|
||||||
|
|
||||||
let key = req.ip // Use the IP address as the key, by default.
|
let key = req.ip // Use the IP address as the key, by default.
|
||||||
|
debugInfo.ip = req.ip
|
||||||
|
|
||||||
// console.log('jwtToken: ', jwtToken)
|
// console.log('jwtToken: ', jwtToken)
|
||||||
|
|
||||||
@@ -236,8 +241,10 @@ class RateLimits {
|
|||||||
|
|
||||||
// Preferentially use the decoded ID in the JWT payload, as the key.
|
// Preferentially use the decoded ID in the JWT payload, as the key.
|
||||||
key = decoded.id
|
key = decoded.id
|
||||||
|
debugInfo.id = key
|
||||||
|
|
||||||
pointsToConsume = decoded.pointsToConsume
|
pointsToConsume = decoded.pointsToConsume
|
||||||
|
debugInfo.pointsToConsume = pointsToConsume
|
||||||
}
|
}
|
||||||
// console.log(`rate limit key: ${key}`)
|
// console.log(`rate limit key: ${key}`)
|
||||||
|
|
||||||
@@ -261,6 +268,10 @@ class RateLimits {
|
|||||||
res.locals.rateLimitTriggered = true
|
res.locals.rateLimitTriggered = true
|
||||||
// console.log('res.locals: ', res.locals)
|
// console.log('res.locals: ', res.locals)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}`
|
||||||
|
)
|
||||||
|
|
||||||
// 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