masasron / adonis-throttle

A rate limiter for Adonis JS
MIT License
64 stars 11 forks source link

Redis #16

Closed kennedyrs closed 4 years ago

kennedyrs commented 4 years ago

When I try to use it with Redis, I have this error

{
  "status": 500,
  "name": "TypeError",
  "message": "this.throttle.store.secondsToExpiration is not a function"
}

Node v12.14.1 Adonis 4.1

is this an error or am I missing something?

masasron commented 4 years ago

@AndrewJo could you take a look?

kennedyrs commented 4 years ago

At file adonis-throttle/middleware/ThrottleRequests.js they try to add a header this.throttle.store.secondsToExpiration(this.throttle.key)

if (!this.throttle.attempt()) {
            this.throttle.incrementExpiration()
            this._addHeaders(
                response,
                maxAttempts,
                this.throttle.remainingAttempts(),
                this.throttle.store.secondsToExpiration(this.throttle.key)
            )
            throw new TooManyRequestsException('Too Many Attempts.')
        }

but at adonis-throttle/src/Drivers/Cache/Redis/index.js this function does not exists

AndrewJo commented 4 years ago

@masasron @kennedyrs submitted PR #17 that fixes this issue!

masasron commented 4 years ago

Great, thank you @AndrewJo