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

feat(index): allow cors to be disabled at route level #332

Merged
merged 2 commits into from
Feb 22, 2025

Conversation

peterfaria-jitb
Copy link
Contributor

I'm submitting this as a Draft PR to gather feedback on my approach.
I'm trying to allow routes to individually enable or disable CORS.
My team finds this useful for creating an API where not all routes
are desirable to be called from a browser.

My proposal is to allow a configuration option, cors: boolean.

Example usage:

  fastify.get<{  }, { cors: boolean }>(
    '/v1/foo/bar',
    {
      config: {
        cors: false,
      },
    },

Checklist

@mcollina
Copy link
Member

This works.

@Fdawgs
Copy link
Member

Fdawgs commented Feb 18, 2025

@peterfaria-jitb Are you wanting to continue this this? I can contribute the tests and documentation to get this moving, as it looks useful!

@Fdawgs Fdawgs marked this pull request as ready for review February 19, 2025 08:55
@Fdawgs Fdawgs changed the title Allow request handlers to individually disable cors feat(index): allow cors to be disabled at route level Feb 19, 2025
@Fdawgs Fdawgs requested a review from a team February 19, 2025 09:00
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Fdawgs Fdawgs merged commit 964b8bb into fastify:main Feb 22, 2025
11 checks passed
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

Successfully merging this pull request may close these issues.

3 participants