Skip to content

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

@3rg0n

Description

@3rg0n

Fider Cloud or Self Hosted
Self Hosted: 0.21.1

Describe the bug
When BASE_URL is configured with a path component (e.g., BASE_URL=https://example.com/feedback), the Context.BaseURL() method strips the path and returns only https://example.com. This breaks all redirects and frontend navigation when Fider is hosted under a subfolder behind a reverse proxy.

The root cause is that there are two BaseURL implementations that behave differently:

Context.BaseURL() (method on Context struct) — used by the renderer and handlers:

// app/pkg/web/context.go:383
func (c *Context) BaseURL() string {
    return c.Request.BaseURL()  // always strips path
}

web.BaseURL() (package-level function) — NOT used by the renderer:

// app/pkg/web/context.go:612
func BaseURL(ctx context.Context) string {
    if env.IsSingleHostMode() {
        return env.Config.BaseURL  // correctly returns full URL with path
    }
    ...
}

Request.BaseURL() only returns scheme://host:port, discarding the path:

// app/pkg/web/request.go:105
func (r *Request) BaseURL() string {
    address := r.URL.Scheme + "://" + r.URL.Hostname()
    if r.URL.Port() != "" {
        address += ":" + r.URL.Port()
    }
    return address  // path is gone
}

The renderer passes ctx.BaseURL() (the context method) to the frontend as Fider.settings.baseURL at app/pkg/web/renderer.go:215, so the frontend also receives a baseURL with no path.

To Reproduce

  1. Set BASE_URL=https://example.com/feedback and HOST_MODE=single
  2. Configure a reverse proxy (e.g., nginx) to forward /feedback/ to Fider, stripping the prefix
  3. Open the Fider UI at https://example.com/feedback/
  4. Perform any action that triggers a redirect (e.g., delete a post, sign in, OAuth callback)
  5. Observe the browser navigates to https://example.com/ instead of https://example.com/feedback/

Expected behavior
Context.BaseURL() should return the full BASE_URL including the path when running in single-host mode, matching the behavior of the package-level web.BaseURL() function. All redirects and frontend navigation should stay within the /feedback/ sub-path.

Additional context
I'm using 0.21.1 of Fider. Self hosted behind a reverse proxy at a sub-path.

The impact is:

  • navigator.goHome() redirects to https://example.com/ instead of https://example.com/feedback/
  • navigator.goTo("/posts/1/my-post") navigates to the wrong location
  • Backend c.Redirect(c.BaseURL()) sends users to the domain root
  • All code relying on c.BaseURL() for redirect targets is broken

Proposed fix:

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

This aligns the context method with the existing package-level BaseURL() function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugsomething is broken, we need to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions