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

fix(vite): use h3 cors handler for vite routes only #23995

Merged
merged 1 commit into from Oct 28, 2023
Merged

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves #22512
resolves #23962

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This turns off vite's cors handler (https://github.com/expressjs/cors) by default, in preference to using h3's handler only for routes to be transformed by vite. This should enable us to avoid CORS headers on Nuxt/Nitro endpoints that aren't handled by vite.

If the user configures vite.server.cors then this is respected.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Oct 28, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pi0
Copy link
Member

pi0 commented Oct 28, 2023

This is good imo for the fix but also we could find a way to disable vite cors overrides entirely allow both consistent behavior when h3 util / route rule used (route rule is normalized to cors headers not using utility) and also user custom behavior

@danielroe
Copy link
Member Author

danielroe commented Oct 28, 2023

I think that is what this fix does. It does disable vite cors header handler entirely and only adds cors headers for vite routes. But maybe I'm misunderstanding you?

@pi0
Copy link
Member

pi0 commented Oct 28, 2023

Indeed it does disable vite feature and directly adds OPTIONS handler via a nuxt default behavior. What i meant was to avoid this too, in next steps iterating with nitro.

@danielroe
Copy link
Member Author

danielroe commented Oct 28, 2023

Ah, I see. But Nuxt only does this for routes that are handled by vite, leaving normal nitro routes unhandled.

What's more, a route rule wouldn't work as the routes are not always predictable.

@danielroe danielroe merged commit 4b2608c into main Oct 28, 2023
33 checks passed
@danielroe danielroe deleted the fix/vite-cors branch October 28, 2023 17:14
@github-actions github-actions bot mentioned this pull request Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants