Added grouping routes for ratelimit#380
Conversation
|
CI is failing |
|
Yeah... There is some issue with the coverage... |
|
Updated the testcases |
|
It is fixed. @gurgunday |
|
Hi @gurgunday / @mcollina Can you please help me with these? Am I missing something with the test? |
|
@gurgunday can you please run the CI again? |
|
I’ll take a look if it’s passing on your end |
|
Hi @gurgunday There was some issue with node_modules and c8. I have fixed them. |
gurgunday
left a comment
There was a problem hiding this comment.
Alright, the implementation LGTM, but I'm not really sure why we need it
Why not just group these routes together and extract them into a plugin? rate-limit supports encapsulation, so why not sth like:
fastify.register(async (fastify) => {
await fastify.register(import("@fastify/rate-limit"), {
max: 3,
timeWindow: "1 minute",
});
fastify.get(
"/otp/send",
(request, reply) => {
reply.send({ hello: "from ... grouped rate limit" });
},
);
fastify.get(
"/otp/resend",
(request, reply) => {
reply.send({ hello: "from ... grouped rate limit" });
},
);
});|
Added it so that it is easily configurable across different route files. |
|
@gurgunday Will this implementation enhance the feature of grouping the routes without encapsulation? |
|
I'm not sure, I feel like we're duplicating functionality and all these small additions might add up to slow down the rate limiter performance @climba03003 @Uzlopak what do you think? Keep in mind #380 (review) already exists |
We have a kind-of-common use case for it: we have several similar endpoints. Some of them should be used from frontend, some from backend and so on. If we use per-route rate limit some clever users start to use all similar endpoints to achieve their task and 50 rps becomes 300 rps |

This PR adds the capability to group various routes and have a common rate limit for them.
#369
Checklist
npm run testandnpm run benchmarkand the Code of conduct