mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c70fc5007 | ||
|
|
b24b659124 | ||
|
|
7ad5acef34 | ||
|
|
304a3f1d5a | ||
|
|
86a58e9ff3 | ||
|
|
d7d722b27b | ||
|
|
d439165dd2 |
@@ -33,7 +33,9 @@ util.inspect.defaultOptions = { depth: 1 }
|
|||||||
// let _this
|
// let _this
|
||||||
|
|
||||||
// Set default rate limit value for testing
|
// Set default rate limit value for testing
|
||||||
const PRO_PASSES = process.env.PRO_PASSES ? process.env.PRO_PASSES : 'testpassword'
|
const PRO_PASSES = process.env.PRO_PASS
|
||||||
|
? process.env.PRO_PASS
|
||||||
|
: 'testpassword'
|
||||||
// Convert the pro-tier password string into an array split by ':'.
|
// Convert the pro-tier password string into an array split by ':'.
|
||||||
const PRO_PASS = PRO_PASSES.split(':')
|
const PRO_PASS = PRO_PASSES.split(':')
|
||||||
|
|
||||||
@@ -47,6 +49,8 @@ class AuthMW {
|
|||||||
// Initialize passport for 'anonymous' authentication.
|
// Initialize passport for 'anonymous' authentication.
|
||||||
passport.use(new AnonymousStrategy())
|
passport.use(new AnonymousStrategy())
|
||||||
|
|
||||||
|
console.log(`PRO_PASS: ${JSON.stringify(PRO_PASS, null, 2)}`)
|
||||||
|
|
||||||
// Initialize passport for 'basic' authentication.
|
// Initialize passport for 'basic' authentication.
|
||||||
passport.use(
|
passport.use(
|
||||||
new BasicStrategy({ passReqToCallback: true }, function (
|
new BasicStrategy({ passReqToCallback: true }, function (
|
||||||
|
|||||||
@@ -12,10 +12,12 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const jwt = require('jsonwebtoken')
|
||||||
|
|
||||||
const wlogger = require('../util/winston-logging')
|
const wlogger = require('../util/winston-logging')
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
|
|
||||||
const jwt = require('jsonwebtoken')
|
const ANON_LIMITS = 50
|
||||||
|
|
||||||
// Redis
|
// Redis
|
||||||
const redisOptions = {
|
const redisOptions = {
|
||||||
@@ -111,7 +113,7 @@ class RateLimits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default value is 50 points per request = 20 RPM
|
// Default value is 50 points per request = 20 RPM
|
||||||
let rateLimit = 50
|
let rateLimit = ANON_LIMITS
|
||||||
|
|
||||||
// Only evaluate the JWT token if the user is not using Basic Authentication.
|
// Only evaluate the JWT token if the user is not using Basic Authentication.
|
||||||
if (!req.locals.proLimit) {
|
if (!req.locals.proLimit) {
|
||||||
@@ -146,6 +148,7 @@ class RateLimits {
|
|||||||
origin &&
|
origin &&
|
||||||
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
||||||
origin.toString().indexOf('sandbox.fullstack.cash') > -1 ||
|
origin.toString().indexOf('sandbox.fullstack.cash') > -1 ||
|
||||||
|
origin.toString().indexOf('splitbch.com') > -1 ||
|
||||||
origin === 'slp-api')
|
origin === 'slp-api')
|
||||||
) {
|
) {
|
||||||
pointsToConsume = 10
|
pointsToConsume = 10
|
||||||
@@ -199,7 +202,7 @@ class RateLimits {
|
|||||||
// Calculates the points consumed, based on the jwt information and the route
|
// Calculates the points consumed, based on the jwt information and the route
|
||||||
// requested.
|
// requested.
|
||||||
calcPoints (jwtInfo) {
|
calcPoints (jwtInfo) {
|
||||||
let retVal = 50 // By default, use anonymous tier.
|
let retVal = ANON_LIMITS // By default, use anonymous tier.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// console.log(`jwtInfo: ${JSON.stringify(jwtInfo, null, 2)}`)
|
// console.log(`jwtInfo: ${JSON.stringify(jwtInfo, null, 2)}`)
|
||||||
@@ -218,12 +221,12 @@ class RateLimits {
|
|||||||
if (level40Routes.includes(resource)) {
|
if (level40Routes.includes(resource)) {
|
||||||
if (apiLevel >= 40) retVal = 10
|
if (apiLevel >= 40) retVal = 10
|
||||||
// else if (apiLevel >= 10) retVal = 10
|
// else if (apiLevel >= 10) retVal = 10
|
||||||
else retVal = 50
|
else retVal = ANON_LIMITS
|
||||||
|
|
||||||
// Normal indexer routes
|
// Normal indexer routes
|
||||||
} else if (level30Routes.includes(resource)) {
|
} else if (level30Routes.includes(resource)) {
|
||||||
if (apiLevel >= 30) retVal = 10
|
if (apiLevel >= 30) retVal = 10
|
||||||
else retVal = 50
|
else retVal = ANON_LIMITS
|
||||||
|
|
||||||
// Full node tier
|
// Full node tier
|
||||||
} else if (apiLevel >= 20) {
|
} else if (apiLevel >= 20) {
|
||||||
@@ -231,7 +234,7 @@ class RateLimits {
|
|||||||
|
|
||||||
// Free tier, full node only.
|
// Free tier, full node only.
|
||||||
} else {
|
} else {
|
||||||
retVal = 50
|
retVal = ANON_LIMITS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +242,7 @@ class RateLimits {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
wlogger.error('Error in route-ratelimit.js/calcPoints()')
|
wlogger.error('Error in route-ratelimit.js/calcPoints()')
|
||||||
// throw err
|
// throw err
|
||||||
retVal = 50
|
retVal = ANON_LIMITS
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal
|
return retVal
|
||||||
|
|||||||
Reference in New Issue
Block a user