-
-
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
Resubmit: Remove group.Use registering Any routes that break other routes #1728
Conversation
There needs to be discussion before this is merged This part // Allow all requests to reach the group as they might get dropped if router
// doesn't find a match, making none of the group middleware process.
g.Any("", NotFoundHandler)
g.Any("/*", NotFoundHandler) was there for a reason - middleware that is attached to group is expected to be fired (example #1701) even if there is no httphandler match within that group (for example to serve static files). Or to be specific - in routing sense/domain there is no such thing as Probably it was not expected that anyone wants to create multiple groups with same path but with different middleware. One example/explanation why it is so #838 basically This is example of mixing API routes with serving static files i.e. g.Use(middleware.Static(""))
g.GET("/api", func(c echo.Context) error {
return c.String(200, "1")
}) Now @segevfiner #1657 problem is valid as those routes ( but just removing any routes would break users static routes attached group. actually workaround for g1 := e.Group("", middleware1())
{
g1.GET("", handler)
}
g2 := e.Group("", middleware2())
{
g2.POST("/other", handler)
} is same as creating slice for group middleware and attaching it as third parameter when attaching http handler to path g1 := e.Group("/users")
authorizedMiddleware := []middleware{middleware1(),checkPermission()}
g1.POST("/:id", handler, authorizedMiddleware)
g1.GET("/", listHandler, authorizedMiddleware)
publicMiddleware := []middleware{middleware2()}
g1.GET("/other", handler, publicMiddleware)
g1.GET("/other/:id", handler2, publicMiddleware) so not to break existing apps serving middleware when these 2 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions. |
I'll leave it closed. This is done in |
This can be a breaking change if this behavior is somehow important to anyone.
Fixes #1657
Resubmit of #1674