mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f4984a982 | ||
|
|
d9fc84f136 | ||
|
|
d444666dec | ||
|
|
c8f3649004 | ||
|
|
ee876ce8e4 | ||
|
|
fbd02802f0 | ||
|
|
6e72879103 | ||
|
|
2817300ad6 | ||
|
|
4aa7cad552 | ||
|
|
5a9401aeb1 | ||
|
|
0ae02790a2 | ||
|
|
4d3adab9e0 | ||
|
|
91f06b6311 | ||
|
|
2fc175d818 | ||
|
|
731861cb1d | ||
|
|
9a01f5ffe6 | ||
|
|
c62c515474 | ||
|
|
ab198b958e | ||
|
|
2618008247 |
Generated
+15724
-273
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -31,7 +31,7 @@
|
|||||||
"node": ">=10.15.1"
|
"node": ">=10.15.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@psf/bch-js": "^4.18.0",
|
"@psf/bch-js": "^4.20.7",
|
||||||
"apidoc": "^0.26.0",
|
"apidoc": "^0.26.0",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"bitcore-lib-cash": "^8.23.1",
|
"bitcore-lib-cash": "^8.23.1",
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
// req.locals.jwtToken property.
|
// req.locals.jwtToken property.
|
||||||
const getTokenFromHeaders = (req, res, next) => {
|
const getTokenFromHeaders = (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
// console.log('req.headers: ', req.headers)
|
||||||
|
|
||||||
// Only executes if the authorization header exists.
|
// Only executes if the authorization header exists.
|
||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
// Retrieve the auth string from the header object.
|
// Retrieve the auth string from the header object.
|
||||||
|
|||||||
@@ -220,11 +220,18 @@ 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,
|
||||||
|
userObj: req.body.usrObj,
|
||||||
|
locals: req.locals
|
||||||
|
}
|
||||||
|
|
||||||
// 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 +243,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 +270,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({
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -175,6 +175,11 @@ class RouteUtils {
|
|||||||
msg: '429 Too Many Requests',
|
msg: '429 Too Many Requests',
|
||||||
status: 429
|
status: 429
|
||||||
}
|
}
|
||||||
|
} else if (err.error.includes('Network error:')) {
|
||||||
|
return {
|
||||||
|
msg: err.error,
|
||||||
|
status: 503
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -73,16 +73,18 @@ describe('#JWTRouter', () => {
|
|||||||
const result = await uut.jwtInfo(req, res)
|
const result = await uut.jwtInfo(req, res)
|
||||||
// console.log('result: ', result)
|
// console.log('result: ', result)
|
||||||
|
|
||||||
assert.property(result, 'id')
|
assert.equal(result.error, 'jwt expired')
|
||||||
assert.property(result, 'email')
|
|
||||||
assert.property(result, 'apiLevel')
|
// assert.property(result, 'id')
|
||||||
assert.property(result, 'rateLimit')
|
// assert.property(result, 'email')
|
||||||
assert.property(result, 'pointsToConsume')
|
// assert.property(result, 'apiLevel')
|
||||||
assert.property(result, 'duration')
|
// assert.property(result, 'rateLimit')
|
||||||
assert.property(result, 'iat')
|
// assert.property(result, 'pointsToConsume')
|
||||||
assert.property(result, 'exp')
|
// assert.property(result, 'duration')
|
||||||
assert.property(result, 'expiration')
|
// assert.property(result, 'iat')
|
||||||
assert.property(result, 'createdAt')
|
// assert.property(result, 'exp')
|
||||||
|
// assert.property(result, 'expiration')
|
||||||
|
// assert.property(result, 'createdAt')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return an error with malformed JWT token', async () => {
|
it('should return an error with malformed JWT token', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user