-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: add OPTIONS
server method
#8731
feat: add OPTIONS
server method
#8731
Conversation
🦋 Changeset detectedLatest commit: 6bdf031 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I sorta feel like Perhaps the default behaviour should be to return a 204 response with I'm not 100% sure what that looks like but it feels like exporting |
|
but why? why wouldn't the server just disregard any headers it wasn't interested in? |
I think it's not just 'would the server be generally interested in these headers?', it's also 'would the server want to trust these headers from this origin?'. CORS wants everything that could potentially be abused to be explicitly opt-in by every server, and not assume that it will filter out things that might be harmful. I've long since stopped trying to second guess the CORS design. But if we want to support it beyond 'idk, you need to respond to the requests in your For this reason, I'd be wary about doing anything fancier than saying the app needs to handle this in its |
Would a combination of CORS helper methods inside an Perhaps there can also be a simpler method of setting CORS options across the board in addition to the manual control of an Or would adding a recipe to the docs for setting CORS in |
Fair enough — that's certainly the path of least resistance.
Very possibly. Though I think it'd be worth shipping this and seeing if people ask for those helpers, rather than blocking on it. I've approved this PR, though since it was marked 'draft' I haven't merged it yet in case there was anything else we wanted to do here first |
Would it be beneficial to make a note in the docs about sveltekit's CORS behaviour during I ask because I wonder if this default behaviour could be misleading for developers creating their own OPTIONS endpoints. Or should a recipe also be added to the docs that explain how to configure pre-flight request in hooks? (would address this recent issue #8963 and others that found #5193 (comment) helpful) Other than that, this PR should be good to go. |
closes #5193
Continues from the work of #6030
OPTIONS
method as valid+server.js
export.Disables Vite config optionspreview.cors
andserver.cors
which were intercepting allOPTIONS
http requests.dev
andpreview
This delegates the responsibility of turning off Vite's CORS middleware to the user when vite's injected headers interfere with development of OPTIONS endpoints.
TODO
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.