From f585312ba42c8e98fb95a9dd37a705d85b6bb63b Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Mon, 22 Oct 2018 22:34:28 +0200 Subject: [PATCH] fix(api): proxy when upstream url has a path Signed-off-by: Sylvain Rabot --- proxy.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxy.go b/proxy.go index c43ff662f..e50abc675 100644 --- a/proxy.go +++ b/proxy.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "net/http" "net/http/httputil" "net/url" @@ -45,6 +46,11 @@ func NewAlertmanagerProxy(alertmanager *alertmanager.Alertmanager) (*httputil.Re // set hostname of proxied target req.Host = upstreamURL.Host + + // Prepend with upstream URL path if exists + if len(upstreamURL.Path) > 0 { + req.URL.Path = strings.TrimSuffix(upstreamURL.Path, "/") + req.URL.Path + } log.Debugf("[%s] Proxy request for %s", alertmanager.Name, req.URL.Path) },