mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a9401aeb1 | ||
|
|
0ae02790a2 | ||
|
|
4d3adab9e0 | ||
|
|
91f06b6311 | ||
|
|
2fc175d818 | ||
|
|
731861cb1d | ||
|
|
9a01f5ffe6 | ||
|
|
c62c515474 | ||
|
|
ab198b958e | ||
|
|
2618008247 |
@@ -12,6 +12,8 @@
|
||||
// req.locals.jwtToken property.
|
||||
const getTokenFromHeaders = (req, res, next) => {
|
||||
try {
|
||||
console.log('req.headers: ', req.headers)
|
||||
|
||||
// Only executes if the authorization header exists.
|
||||
if (req.headers.authorization) {
|
||||
// Retrieve the auth string from the header object.
|
||||
@@ -21,7 +23,7 @@ const getTokenFromHeaders = (req, res, next) => {
|
||||
if (authStr.split(' ')[0] === 'Token') {
|
||||
const token = authStr.split(' ')[1]
|
||||
|
||||
// console.log(`JWT found: ${token}`)
|
||||
console.log(`JWT found: ${token}`)
|
||||
|
||||
// Create the req.locals property if it does not yet exist.
|
||||
if (!req.locals) {
|
||||
|
||||
@@ -220,11 +220,18 @@ class RateLimits {
|
||||
// it will return the 'res' object with an error status and message, which
|
||||
// should be returned by the middleware.
|
||||
async trackRateLimits (req, res, jwtToken) {
|
||||
const debugInfo = {
|
||||
jwtToken,
|
||||
userObj: req.body.usrObj,
|
||||
locals: req.locals
|
||||
}
|
||||
|
||||
// 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.
|
||||
debugInfo.ip = req.ip
|
||||
|
||||
// console.log('jwtToken: ', jwtToken)
|
||||
|
||||
@@ -236,8 +243,10 @@ class RateLimits {
|
||||
|
||||
// Preferentially use the decoded ID in the JWT payload, as the key.
|
||||
key = decoded.id
|
||||
debugInfo.id = key
|
||||
|
||||
pointsToConsume = decoded.pointsToConsume
|
||||
debugInfo.pointsToConsume = pointsToConsume
|
||||
}
|
||||
// console.log(`rate limit key: ${key}`)
|
||||
|
||||
@@ -261,6 +270,10 @@ class RateLimits {
|
||||
res.locals.rateLimitTriggered = true
|
||||
// console.log('res.locals: ', res.locals)
|
||||
|
||||
console.log(
|
||||
`rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}`
|
||||
)
|
||||
|
||||
// Rate limited was triggered
|
||||
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||
return res.json({
|
||||
|
||||
Reference in New Issue
Block a user