masasron / adonis-throttle

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

Throttle records the same with 2 routes. #7

Closed jericopulvera closed 6 years ago

jericopulvera commented 6 years ago

Hi. I have this 2 route but I want the request record on them to be the same.

    Route.post('raffles-like', 'RaffleLikeController.store').middleware([
        'customAuth', 'throttle:20,30'
    ])
    Route.delete('raffles-like/:productId', 'RaffleLikeController.destroy').middleware([
        'customAuth', 'throttle:20,30'
    ])

What's currently happening is that when I like a product and reach the throttle limit, I would still be able to, unlike the product.

What I want to happen is that when Liking throttle limit is reached it should be the same with unlike.

Like this.

    Route.post('raffles-like', 'RaffleLikeController.store').middleware([
        'customAuth', 'throttle-like:20,30'
    ])
    Route.delete('raffles-like/:productId', 'RaffleLikeController.destroy').middleware([
        'customAuth', 'throttle-like:20,30'
    ])

How do I achieve this?

masasron commented 6 years ago

Hi @jericopulvera,

I currently generate a signature for each route like so request method + path + user IP. https://github.com/masasron/adonis-throttle/blob/master/middleware/ThrottleRequests.js#L71

You can overwrite this value when by using the Throttle object directly. https://github.com/masasron/adonis-throttle#advance

I would just create a new middleware that removes the request method from the signature.