fastify-cors
fastify-cors copied to clipboard
logLevel option not respected
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.28.1
Plugin version
9.0.1
Node.js version
18.20.2
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.4 LTS
Description
It would be nice to exclude OPTIONS requests from the logs
Link to code that reproduces the bug
No response
Expected Behavior
No response
There is not an instance of logging in this module https://github.com/search?q=repo%3Afastify%2Ffastify-cors%20log&type=code
This module registers route handler and fastify logs requests to the route like it does for any route. But for user-defined route it is possible to customize log level and mute particular routes requests:
fastify.get('/', { logLevel: 'warn' }, (request, reply) => {
reply.send({ hello: 'world' })
})
Yet, there is no way to push logLevel option into the route registered by this module.
// The preflight reply must occur in the hook. This allows fastify-cors to reply to
// preflight requests BEFORE possible authentication plugins. If the preflight reply
// occurred in this handler, other plugins may deny the request since the browser will
// remove most headers (such as the Authentication header).
//
// This route simply enables fastify to accept preflight requests.
fastify.options('*', { schema: { hide: hideOptionsRoute } }, (req, reply) => {
if (!req.corsPreflightEnabled) {
// Do not handle preflight requests if the origin option disabled CORS
reply.callNotFound()
return
}
reply.send()
})
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Example: https://github.com/fastify/csrf-protection/pull/186
I am working on this issue