Fix wildcard path join with trailing slash and respect req path
@@ -284,6 +284,11 @@ func (p *Proxy) director(req *http.Request) {
if pathMatch, ok := req.Context().
Value(request.Wildcard).(string); ok && strings.HasSuffix(p.options.Path, "/**") {
+ if pathMatch == "" { // wildcard "root" hit, take a look if the req has a trailing slash and apply
+ if req.URL.Path[len(req.URL.Path)-1] == '/' {
+ pathMatch = "/"
+ }
+ }
req.URL.Path = utils.JoinPath(strings.ReplaceAll(p.options.Path, "/**", "/"), pathMatch)
} else if p.options.Path != "" {
req.URL.Path = p.options.Path
