-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added grouping routes for ratelimit #380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
CI is failing |
Yeah... There is some issue with the coverage... |
Updated the testcases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's still red
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR adds the capability to group various routes and have a common rate limit for them.
#369
Checklist
npm run test
andnpm run benchmark
and the Code of conduct