diff --git a/src/middleware/route-ratelimit.js b/src/middleware/route-ratelimit.js index 7554acd..961ea82 100644 --- a/src/middleware/route-ratelimit.js +++ b/src/middleware/route-ratelimit.js @@ -40,6 +40,8 @@ class RateLimits { this.rateLimiter = new RateLimiterRedis(rateLimitOptions) } + // Used to disconnect from the Redis DB. + // Called by unit tests so that node.js thread doesn't live forever. closeRedis() { redisClient.disconnect() } @@ -228,9 +230,7 @@ class RateLimits { /* This is the new rate limit function that uses the rate-limiter-flexible npm - library. For the moment, it only distinguishes between anonymous usage - and registered user access. anon usage allows up to 3 RPM, whereas registered - users (with JWT tokens) have 100 RPM. + library. */ async newRateLimit(req, res, next) { try { @@ -353,7 +353,7 @@ class RateLimits { // what kind of variations will be seen in production. getResource(url) { try { - console.log(`url: ${JSON.stringify(url, null, 2)}`) + // console.log(`url: ${JSON.stringify(url, null, 2)}`) const splitUrl = url.split("/") const resource = splitUrl[1] diff --git a/test/v3/rate-limits.js b/test/v3/rate-limits.js index 79f4fb1..db237cb 100644 --- a/test/v3/rate-limits.js +++ b/test/v3/rate-limits.js @@ -240,6 +240,18 @@ describe("#route-ratelimits & jwt-auth", () => { ) }) }) + + describe("#getResource", () => { + it("should decode a blockchain request", () => { + const url = + "/blockchain/getTxOut/62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8/0?include_mempool=true" + + const result = rateLimits.getResource(url) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.equal(result, "blockchain") + }) + }) }) // Generates a Basic authorization header.