How to handle CORS Preflight (OPTIONS)? #818
Unanswered
JASKevinWhite
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using the Humago router on Huma 2.32.0.
I'm needing to send the 3 CORS headers, the usual. I attached some middleware, and now all of my endpoints properly contain the CORS headers. The middleware contains this:
The problem is, this never gets called. The issue is, none of my endpoints are registered with a Method: http.MethodOptions, so the calls apparently get rejected before the middleware even runs.
I was hoping that there would be a general pupose way for me to just accept OPTIONS on anything I have an endpoint on and return it with the headers set and a 204.
I can register each endpoint a second time with Method: http.MethodOptions, but this is messy. First, because each endpoint is duplicated, and second, because the docs show each endpoint twice, with the OPTIONS entry and the original one.
I just don't know if there's a more clever way to handle this situation.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions