fastify / fastify-rate-limit

A low overhead rate limiter for your routes
MIT License
504 stars 71 forks source link

Refactor `index.js` to fix multiple bugs #326

Closed gurgunday closed 1 year ago

gurgunday commented 1 year ago

Here's what it fixes concretely:

https://github.com/fastify/fastify-rate-limit/blob/18df4d3a33d32bf9c71f2d842117140e7e3b4bfc/index.js#L190-L198

https://github.com/fastify/fastify-rate-limit/blob/18df4d3a33d32bf9c71f2d842117140e7e3b4bfc/index.js#L118-L123

Now, the decorator and the config property behave exactly the same

The reason for moving objects out of the main function is that, as this plugin supports being registered multiple times with multiple stores, we risk recreating these objects every single time

And finally, I tried to minimize the amount of intermediate objects that are created