Closed DiogoMarques2003 closed 1 year ago
and like if i have '/api/docs/*' in array the system exclude rate limit of all paths started for this
Just a reminder that you can already register rate-limit to specific routes using Fastify’s encapsulation. It’s not exactly an allowPaths but it works just as well.
Just a reminder that you can already register rate-limit to specific routes using Fastify’s encapsulation. It’s not exactly an allowPaths but it works just as well.
How to do this ? Can you give a example pls ?
const app = fastify()
app.register(async function () {
app.register(require('@fastify/rate-limit'), {
})
// put all the routes to rate limit here
})
app.register(async function () {
// put all the routes to not rate limit here
})
Hy @mcollina I already try this, but this don't work because the route is /api/docs ...
I'm not sure how that prevents you to define /docs inside the other plugin.
@mcollina Because in /api/docs I don't want to have ratelimit
This should work:
const app = fastify()
app.register(async function () {
app.register(require('@fastify/rate-limit'), {
})
// put all the routes to rate limit here
})
app.register(async function () {
// put all the routes to not rate limit here
app.get('/api/docs', ()=> ...)
})
Ok, but the /api/docs in one plugin, exists some problem ?
There should not be any problems.
Okok, but if I make this feature, will it be accepted?
No, I don't think so.
There is even a better way to declare a route without rate limiting (https://github.com/fastify/fastify-rate-limit/blob/4b78b2efabb9abddc746cc0c88597230157403d1/index.js#L139):
app.get('/', { config: { rateLimit: false } }, () => ...)
Prerequisites
🚀 Feature Proposal
It's possible add a system like allowList, but for paths in api ?
Motivation
I want this because one plugin register one route, and on this route I can't have rate limit
Example