-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
middleware.CORSConfig can not be configured per path #2620
Comments
@rpstw Note that As for applying different CORS middleware on different routes, I believe that Echo allows you to do that. This example uses a different CORS library, but you should be able to adapt it to your needs. |
When you add GET route with CORS middleware with e.Add(
http.MethodGet,
"/some/path",
SomeHandlerFunc,
middleware.CORSWithConfig(middleware.CORSConfig{
AllowCredentials: true,
}),
) Echo router registers only node matching GET method in its internal routing tree. So when you issue OPTION method call to same path the CORS middleware do not get executed as it is tied (wrapping it) to GET handler. So CORS middleware is best to be used with p.s. if choose to register own OPTIONS routes you can use Line 356 in 88c379f
|
Thanks for the explanation. |
Issue Description
The following code tris to configure CORS per path.However, due to
optionsMethodHandler
ignoring all configured middlewares, a preflight request will receive a bad response which contains no Access-Control-Allow headers.Checklist
Expected behaviour
Actual behaviour
Steps to reproduce
As described above
Working code to debug
As described above
Version/commit
tried 4.11.4 and 4.10.2
Workarounds tried
As #2039 inspired, configuring a custom
OPTIONS
route can bypass the code whereoptionsMethodHandler
ignoring middlewaresI'm not sure if I'm configuring CORS in a popular doable way, also the reproducible example is excerpted from a development environment which may not be as realistic as a real prod server case. Any suggestions are welcome.
The text was updated successfully, but these errors were encountered: