Closed ruturajmore closed 2 years ago
Let me check this @ruturajmore
So basically you want rate limiter only for one api and disabled for all others ? @ruturajmore
Yes, the intention behind using a decorator is to enable rate-limiting for some required APIs. But it is not working as expected. Requests are not getting blocked even after max attempts. There no error in logs. @samarpan-b
Thats because you have removed it from sequence. Decorator is not meant to do the rate limiting. Decorator is meant to provide it the config. The actual rate-limiting is performed by sequence action during the request capture in sequence. That's what decorator pattern means actually. Can you enable it in sequence and try again ?
This component also exposes a method decorator for cases where you want tp specify different rate limiting options at API method level. For example, you want to keep hard rate limit for unauthorized API requests and want to keep it softer for other API requests. In this case, the global config will be overwritten by the method decoration. Refer below.
Check it out in docs. Also for disabling rate limiting from apis you can just do @ratelimit(false)
Yes, I checked it's working. One last thing, default windowMs is not getting overridden even through the decorator. Thanks for your support @samarpan-b !!!
We'll check that tomorrow @ruturajmore when @akshatdubeysf is back. Will that be fine ?
Yes, it would be great. Thanks! @samarpan-b
Observed one more weird thing when findRoute() and parseParams() are called after rateLimitAction(), decorator's configs are ignored and global configs are used.
sequence.ts
await this.rateLimitAction(request, response);
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
Can you please check? @samarpan-b @akshatdubeysf
@ruturajmore thats how loopback sequence works. The decorator config is only read when you parsed the params. If you try to do it before that, it will not work. So better to invoke it afterwards only. Parse params and find route is responsible for identifying the controller method for the API. Hence it is needed before.
Fixed through a PR hence closing this
Hi there, ratelimit decorator is not working.
controller.ts
application.ts
package.json
@samarpan-b can you please check? Thanks in advance!