Skip to content

fix: Context.BaseURL() discards path when HOST_MODE=single#1502

Open
tejasae-afk wants to merge 1 commit intogetfider:mainfrom
tejasae-afk:fix/context-base-url-single-host-mode
Open

fix: Context.BaseURL() discards path when HOST_MODE=single#1502
tejasae-afk wants to merge 1 commit intogetfider:mainfrom
tejasae-afk:fix/context-base-url-single-host-mode

Conversation

@tejasae-afk
Copy link
Copy Markdown

When HOST_MODE=single and BASE_URL contains a path component (e.g. https://example.com/feedback), Context.BaseURL() was returning only the scheme and host (https://example.com), silently dropping the path.

This broke server-side redirects (sign-in, OAuth callbacks, delete-post flows, etc.) and the baseURL value injected into the frontend via the renderer — all of which call c.BaseURL(). Users hosted behind a reverse proxy under a sub-path would land on the root of the site instead of the configured sub-path after any redirect.

The root cause is a split between two BaseURL implementations. The package-level web.BaseURL(ctx) already handled single-host mode correctly by returning env.Config.BaseURL intact, but Context.BaseURL() always delegated to Request.BaseURL(), which only constructs scheme://host:port with no path.

The fix is one extra check at the top of Context.BaseURL():

func (c *Context) BaseURL() string {
    if env.IsSingleHostMode() {
        return env.Config.BaseURL
    }
    return c.Request.BaseURL()
}

This makes Context.BaseURL() consistent with web.BaseURL(). Multi-tenant behaviour is unchanged.

A test covering the single-host-with-path case is included.

Fixes #1452.

you know the codebase far better than I do, happy to adjust anything here.

When HOST_MODE=single and BASE_URL contains a path component (e.g.
https://example.com/feedback), Context.BaseURL() was returning only
the scheme+host (https://example.com), discarding the path.

This broke all server-side redirects and the baseURL injected into
the frontend because handlers call c.BaseURL() — not the package-level
web.BaseURL() function, which already handled single-host mode
correctly.

The fix aligns Context.BaseURL() with web.BaseURL(): when in
single-host mode it returns env.Config.BaseURL directly. The
multi-tenant path is unchanged.

Fixes getfider#1452
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Context.BaseURL() strips path from BASE_URL, breaking subfolder/sub-path hosting

1 participant