From f7e39fb8e15de25faf9f331b1956d8d7254368d4 Mon Sep 17 00:00:00 2001 From: Ergon Copeland <62959009+3rg0n@users.noreply.github.com> Date: Wed, 11 Feb 2026 11:54:02 +0000 Subject: [PATCH] fix: Context.BaseURL() now returns full BASE_URL in single-host mode Context.BaseURL() was always calling Request.BaseURL() which only returns scheme://host:port, stripping any path component from the configured BASE_URL. This broke all redirects and frontend navigation when Fider is hosted under a sub-path (e.g., BASE_URL=https://example.com/feedback). The package-level web.BaseURL() function already handled this correctly by returning env.Config.BaseURL in single-host mode. This change aligns the Context method with that behavior. Fixes #1452 Co-Authored-By: Claude Opus 4.6 --- app/pkg/web/context.go | 3 +++ app/pkg/web/context_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) 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)