Exclude paths/routes from 503 errors
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
In some cases you do not want to trigger the "Service Unavailable" 503 error, a very good example would be the Swagger documentation page.
Meaning there should be an option for some kind of whitelist.
Motivation
Some pages or routes shouldn't be blocked, for example I would like to keep showing the Swagger Docs page, even if the healthCheck fails for instance.
Example
Just an proto-type idea for such an interface by introducing an option like routeWhitelist:
fastify.register(require('@fastify/under-pressure'), {
maxEventLoopDelay: 1000,
routeWhitelist: ['/docs'],
})
An alternative solution is to provide a config option to the route config settings for under-pressure. Just like you can set a log level per route, you should be able to "ignore" the route from under-pressure plugin.
Instead of providing the paths in plugin options, we can also inspect the route options.
fastify.get('/bypass', {
config: {
underPressure: {
bypass: true
}
}
}, async function() {
return { ok: true }
})
That is what I was saying as well as my alternative solution above. So let's go with that solution then, since the alternative solution using route configs is maybe better.
EDIT: Anyway, I will pick up this item. This should be durable to do for me.
You can do this:
const bypassPressure = {
config: {
pressureHandler: () => {}
}
}
fastify.post('/', bypassPressure, async (request, reply) => {
// ...
})
I guess I fixed this last week! Thanks @HyperCrowd.
I guess I fixed this last week! Thanks @HyperCrowd.
You did. Thanks! pressureHandler is the way now.
Wait... I proposed a config for under-pressure plugin specifically. This is adding an option for routes. Which is cool ofc.
However, now have the following code for configuring the Swagger route:
await fastify.register(fastifySwaggerUi, {
routePrefix: '/docs',
logLevel: 'silent'
})
How can I set pressureHandler to an empty function? Since @fastify/swagger-ui is a plugin with a routePrefix option. I don't see any option to provide route configs. After all, my request was about the swagger documentation page.
@mcollina could you re-open the issue? Unless you think I can provide route options to the fastify.register() function or an option on @fastify/swagger-ui? Or.. do you want to change https://github.com/fastify/fastify-swagger-ui instead?