Frontend Service: Client side redirect to custom domain (#113717)

* handle redirect in frontend service

* add comments
This commit is contained in:
Ashley Harrison
2025-11-13 03:32:14 +00:00
committed by GitHub
parent 6c8c4c32b5
commit 3563388d4d
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -32,6 +32,16 @@ func ValidateHostHeader(cfg *setting.Cfg) web.Handler {
}
if !strings.EqualFold(h, cfg.Domain) {
// the normal redirecting logic doesn't work when running as frontend service, since it has no knowledge of the custom domain.
// instead, we modify the single tenant `/bootdata` call with a 204 response and a header indicating the domain to redirect to
// this is safe because only the frontend service calls `/bootdata`
// the redirect is then handled client side.
// see pkg/services/frontend/index.html
if c.Req.URL.Path == "/bootdata" {
c.Resp.Header().Set("Redirect-Domain", cfg.Domain)
c.Resp.WriteHeader(204)
return
}
hostRedirectCounter.Inc()
c.Logger.Info("Enforcing Host header", "hosted", c.Req.Host, "expected", cfg.Domain)
c.Redirect(strings.TrimSuffix(cfg.AppURL, "/")+c.Req.RequestURI, 301)