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
- Set
BASE_URL=https://example.com/feedback and HOST_MODE=single
- Configure a reverse proxy (e.g., nginx) to forward
/feedback/ to Fider, stripping the prefix
- Open the Fider UI at
https://example.com/feedback/
- Perform any action that triggers a redirect (e.g., delete a post, sign in, OAuth callback)
- 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.
Fider Cloud or Self Hosted
Self Hosted: 0.21.1
Describe the bug
When
BASE_URLis configured with a path component (e.g.,BASE_URL=https://example.com/feedback), theContext.BaseURL()method strips the path and returns onlyhttps://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
BaseURLimplementations that behave differently:Context.BaseURL()(method on Context struct) — used by the renderer and handlers:web.BaseURL()(package-level function) — NOT used by the renderer:Request.BaseURL()only returnsscheme://host:port, discarding the path:The renderer passes
ctx.BaseURL()(the context method) to the frontend asFider.settings.baseURLatapp/pkg/web/renderer.go:215, so the frontend also receives abaseURLwith no path.To Reproduce
BASE_URL=https://example.com/feedbackandHOST_MODE=single/feedback/to Fider, stripping the prefixhttps://example.com/feedback/https://example.com/instead ofhttps://example.com/feedback/Expected behavior
Context.BaseURL()should return the fullBASE_URLincluding the path when running in single-host mode, matching the behavior of the package-levelweb.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 tohttps://example.com/instead ofhttps://example.com/feedback/navigator.goTo("/posts/1/my-post")navigates to the wrong locationc.Redirect(c.BaseURL())sends users to the domain rootc.BaseURL()for redirect targets is brokenProposed fix:
This aligns the context method with the existing package-level
BaseURL()function.