-
-
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
Preflight/OPTIONS request return 405 for groups with cors/middleware #1040
Comments
Hello, just wanted to follow up on this issue. Is this a valid concern? Or is there a recommended alternative approach? Thank you. |
I am having the same issue. Requests to the grouped endpoint are failing the preflight when they shouldn't be. |
same issue , any news? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I too am having same issue. any workaround? |
Me too. Any workaround? |
Got this too |
There seems to be an issue with echo's trailing slashes |
The solution is to use |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Adding
Is not a fix for me. |
I am yet to understand where this goes wrong :) |
What I can conclude, so far.
At this level, it will always get called as part of the highest level middleware. The simplest, just add it there and be happy. Anything else, will make you frustrated and not help. I think where I went wrong and perhaps others, is the concept, that middleware via Use can be used at the top level and in groups etc, however this particular middleware only works correctly in one spot. @vishr is that fair to say? |
@freshteapot This is my understanding as well. There are basically two distinct types of middleware in Echo:
Despite the similarity between My workaround has been to just declare a dummy g := e.Group("")
g.Use(middleware.CORSWithConfig(...)) // CORS middleware applied to group
g.GET("/foo", myHandler) // Normal handler
g.OPTIONS("/foo", echo.MethodNotAllowedHandler) // Dummy handler If you have lots of routes, you can define a new type that wraps type CORSGroup struct {
g *echo.Group
}
func (cg *CORSGroup) GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) {
cg.g.GET(path, h, m...) // Normal handler
cg.g.OPTIONS(path, echo.MethodNotAllowedHandler) // Dummy handler
}
// POST, DELETE, etc. |
You can always migrate to fiber v2. :D because curl -I host:port/ -v still return 405 . There is no shortage of routers |
Linking it here #2039 adds |
The 405 I am seeing happens when:
I want to acknowledge that this is very similar to #228. However, it seems recently other people have commented that they are experiencing a similar issue and did not see a response.
To reproduce, example when CORS is added to a group only and OPTIONS returns 405
curl -i -X OPTIONS http://localhost:8083/group/test
However, if the CORS is added at the main route level (this is not what we want to do), OPTIONS returns ideal response:
curl -i -X OPTIONS http://localhost:8083/group/test
Ideally, it would be nice when adding CORS at the group level only (see code in first example), that a 204 and all of the access-control headers is returned for preflight/options requests (see curl response in second example).
Note: using Echo version 3
The text was updated successfully, but these errors were encountered: