-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
The proxy middleware is not forwarding requests #1808
Comments
This is current limitation of Echo router. It finds match for Unless you want to wait for fix you can work around this problem by using func TestProxy(t *testing.T) {
targetEcho := echo.New()
g1 := targetEcho.Group("/api")
g1.Any("/*", func(c echo.Context) error {
fmt.Println("targetEcho: " + c.Path())
return c.String(http.StatusOK, fmt.Sprintf("response from targetEcho: %v\n", c.Path()))
})
g1.GET("/resource/:id", func(c echo.Context) error {
fmt.Println("targetEcho: " + c.Path())
return c.String(http.StatusOK, fmt.Sprintf("response from targetEcho: %v\n", c.Path()))
})
e1url, _ := url.Parse("http://localhost:8084")
proxyingEcho := echo.New()
g2 := proxyingEcho.Group("/api")
g2.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{
Skipper: func(e echo.Context) bool {
if e.Request().Method == http.MethodPut && strings.HasPrefix(e.Request().URL.Path, "/api/resource/") {
return true
}
return false
},
Balancer: middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{
{
URL: e1url, // forward all requests with /api prefix to server running on port 8084 (except PUT /resource/:id)
},
}),
}),
)
g2.Any("/resource/:id", func(c echo.Context) error {
return errors.New("never reached")
})
g2.PUT("/resource/:id", func(c echo.Context) error {
fmt.Println("proxyingEcho: " + c.Path())
return c.String(http.StatusOK, fmt.Sprintf("response from proxyingEcho: %v\n", c.Path()))
})
go targetEcho.Start(":8084")
if err := proxyingEcho.Start(":8088"); err != nil {
log.Fatal(err)
}
} x@x:~/code$ curl -X GET http://localhost:8088/api/resource/1
response from targetEcho: /api/resource/:id
x@x:~/code$ curl -X PUT http://localhost:8088/api/resource/1
response from proxyingEcho: /api/resource/:id
x@x:~/code$ curl -X PUT http://localhost:8088/api/should_proxy
response from targetEcho: /api/*
x@x:~/code$ curl -X GET http://localhost:8088/api/should_proxy
response from targetEcho: /api/* |
Is there any future plan to fix this issue? |
…ot then continue search in tree (fix labstack#1808)
Issue Description
The proxy middleware is not forwarding requests
Expected behaviour
Middleware should be called to forward request to the another echo instance
Actual behaviour
Middleware is not called and I'm getting back a 405 status code (method not allowed)
Steps to reproduce
Working code to debug
The text was updated successfully, but these errors were encountered: