How to handle CORS Preflight (OPTIONS)? #818
-
|
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.
Replies: 1 comment 1 reply
-
|
Hey @JASKevinWhite! My apologies if I'm misunderstanding, but in my APIs, I handle this using a mux middleware rather than within Huma :) |
Beta Was this translation helpful? Give feedback.
Hey @JASKevinWhite! My apologies if I'm misunderstanding, but in my APIs, I handle this using a mux middleware rather than within Huma :)