fix(api): use relative URIs for proxy endpoints

Fixes #3060.
This commit is contained in:
Łukasz Mierzwa
2021-05-03 19:29:09 +01:00
committed by Łukasz Mierzwa
parent e45debed58
commit b7f0f0cc33
2 changed files with 11 additions and 17 deletions

View File

@@ -4,13 +4,11 @@ import (
"fmt"
"net/http"
"net/url"
"path"
"sort"
"strings"
"sync"
"time"
"github.com/prymitive/karma/internal/config"
"github.com/prymitive/karma/internal/filters"
"github.com/prymitive/karma/internal/mapper"
"github.com/prymitive/karma/internal/models"
@@ -183,11 +181,7 @@ func (am *Alertmanager) pullSilences(version string) error {
// InternalURI is the URI of this Alertmanager that will be used for all request made by the UI
func (am *Alertmanager) InternalURI() string {
if am.ProxyRequests {
sub := fmt.Sprintf("/proxy/alertmanager/%s", am.Name)
if strings.HasPrefix(config.Config.Listen.Prefix, "/") {
return path.Join(config.Config.Listen.Prefix, sub)
}
return path.Join("/"+config.Config.Listen.Prefix, sub)
return fmt.Sprintf("./proxy/alertmanager/%s", am.Name)
}
// strip all user/pass information, fetch() doesn't support it anyway

View File

@@ -33,13 +33,13 @@ var uriTests = []uriTest{
{
rawURI: "http://alertmanager.example.com",
proxy: true,
internalURI: "/proxy/alertmanager/test",
internalURI: "./proxy/alertmanager/test",
publicURI: "http://alertmanager.example.com",
},
{
rawURI: "http://alertmanager.example.com/foo",
proxy: true,
internalURI: "/proxy/alertmanager/test",
internalURI: "./proxy/alertmanager/test",
publicURI: "http://alertmanager.example.com/foo",
},
{
@@ -57,21 +57,21 @@ var uriTests = []uriTest{
{
rawURI: "http://user:pass@alertmanager.example.com",
proxy: true,
internalURI: "/proxy/alertmanager/test",
internalURI: "./proxy/alertmanager/test",
publicURI: "http://user:pass@alertmanager.example.com",
},
{
rawURI: "http://user:pass@alertmanager.example.com",
extURI: "http://am.example.com",
proxy: true,
internalURI: "/proxy/alertmanager/test",
internalURI: "./proxy/alertmanager/test",
publicURI: "http://am.example.com",
},
{
rawURI: "http://alertmanager.example.com",
extURI: "http://am.example.com",
proxy: true,
internalURI: "/proxy/alertmanager/test",
internalURI: "./proxy/alertmanager/test",
publicURI: "http://am.example.com",
},
{
@@ -134,27 +134,27 @@ func TestAlertmanagerInternalURI(t *testing.T) {
{
prefix: "/",
proxy: true,
uri: "/proxy/alertmanager/default",
uri: "./proxy/alertmanager/default",
},
{
prefix: "/root",
proxy: true,
uri: "/root/proxy/alertmanager/default",
uri: "./proxy/alertmanager/default",
},
{
prefix: "/root/",
proxy: true,
uri: "/root/proxy/alertmanager/default",
uri: "./proxy/alertmanager/default",
},
{
prefix: "root",
proxy: true,
uri: "/root/proxy/alertmanager/default",
uri: "./proxy/alertmanager/default",
},
{
prefix: "root/",
proxy: true,
uri: "/root/proxy/alertmanager/default",
uri: "./proxy/alertmanager/default",
},
}