Skip to content
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

logLevel option not respected #320

Open
2 tasks done
vatosarmat opened this issue Sep 19, 2024 · 3 comments
Open
2 tasks done

logLevel option not respected #320

vatosarmat opened this issue Sep 19, 2024 · 3 comments

Comments

@vatosarmat
Copy link

Prerequisites

  • I have written a descriptive issue title
  • 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

@jsumners
Copy link
Member

There is not an instance of logging in this module https://github.com/search?q=repo%3Afastify%2Ffastify-cors%20log&type=code

@vatosarmat
Copy link
Author

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()
  })

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants