mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Merge branch 'master' into nft-get-calls
This commit is contained in:
@@ -154,6 +154,7 @@ class RateLimits {
|
||||
res,
|
||||
defaultJwt
|
||||
)
|
||||
// console.log(`hasExceededRateLimit: `, hasExceededRateLimit)
|
||||
|
||||
if (!hasExceededRateLimit) {
|
||||
// Rate limits have not been exceeded. Processing can continue.
|
||||
@@ -195,6 +196,7 @@ class RateLimits {
|
||||
res,
|
||||
req.locals.jwtToken
|
||||
)
|
||||
// console.log('hasExceededRateLimit: ', hasExceededRateLimit)
|
||||
|
||||
if (!hasExceededRateLimit) {
|
||||
// Rate limits have not been exceeded. Processing can continue.
|
||||
@@ -220,8 +222,12 @@ class RateLimits {
|
||||
async trackRateLimits (req, res, jwtToken) {
|
||||
// Anonymous rate limits are used by default.
|
||||
let pointsToConsume = ANON_LIMITS
|
||||
// console.log('pointsToConsume: ', pointsToConsume)
|
||||
|
||||
let key = req.ip // Use the IP address as the key, by default.
|
||||
|
||||
// console.log('jwtToken: ', jwtToken)
|
||||
|
||||
try {
|
||||
// Decode the JWT token if it exists
|
||||
if (jwtToken) {
|
||||
@@ -239,6 +245,10 @@ class RateLimits {
|
||||
// The 429 error response is handled by the catch().
|
||||
await _this.rateLimiter.consume(key, pointsToConsume)
|
||||
|
||||
// Debugging
|
||||
// const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume)
|
||||
// console.log(`rateLimitData: `, rateLimitData)
|
||||
|
||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||
|
||||
// Signal that the user has not exceeded their rate limits.
|
||||
|
||||
Reference in New Issue
Block a user