diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go index 64f636400..23a0f8aa9 100644 --- a/app/pkg/web/context.go +++ b/app/pkg/web/context.go @@ -381,6 +381,9 @@ func (c *Context) RemoveCookie(name string) { // BaseURL returns base URL func (c *Context) BaseURL() string { + if env.IsSingleHostMode() { + return env.Config.BaseURL + } return c.Request.BaseURL() } diff --git a/app/pkg/web/context_test.go b/app/pkg/web/context_test.go index 8bf097095..6224f22c1 100644 --- a/app/pkg/web/context_test.go +++ b/app/pkg/web/context_test.go @@ -51,6 +51,7 @@ func TestContextID(t *testing.T) { func TestBaseURL(t *testing.T) { RegisterT(t) + env.Config.HostMode = "multi" ctx := newGetContext("http://demo.test.fider.io:3000", nil) @@ -59,6 +60,7 @@ func TestBaseURL(t *testing.T) { func TestBaseURL_HTTPS(t *testing.T) { RegisterT(t) + env.Config.HostMode = "multi" ctx := newGetContext("https://demo.test.fider.io:3000", nil) @@ -67,6 +69,7 @@ func TestBaseURL_HTTPS(t *testing.T) { func TestBaseURL_HTTPS_Proxy(t *testing.T) { RegisterT(t) + env.Config.HostMode = "multi" ctx := newGetContext("http://demo.test.fider.io:3000", map[string]string{ "X-Forwarded-Proto": "https", @@ -75,6 +78,26 @@ func TestBaseURL_HTTPS_Proxy(t *testing.T) { Expect(ctx.BaseURL()).Equals("https://demo.test.fider.io:3000") } +func TestBaseURL_SingleHostMode(t *testing.T) { + RegisterT(t) + env.Config.HostMode = "single" + env.Config.BaseURL = "https://example.com" + + ctx := newGetContext("http://demo.test.fider.io:3000", nil) + + Expect(ctx.BaseURL()).Equals("https://example.com") +} + +func TestBaseURL_SingleHostMode_WithPath(t *testing.T) { + RegisterT(t) + env.Config.HostMode = "single" + env.Config.BaseURL = "https://example.com/feedback" + + ctx := newGetContext("http://demo.test.fider.io:3000", nil) + + Expect(ctx.BaseURL()).Equals("https://example.com/feedback") +} + func TestCurrentURL(t *testing.T) { RegisterT(t)