fix(backend): redirect index.html to /

Fixes #7069
This commit is contained in:
Łukasz Mierzwa
2026-08-14 11:49:44 +01:00
committed by Łukasz Mierzwa
parent b60e349d7e
commit df80493dd9
4 changed files with 26 additions and 0 deletions
+6
View File
@@ -1,5 +1,11 @@
# Changelog
## v0.133
### Changed
- Requests for `/index.html` will now be redirected to `/` - #7069.
## v0.132
### Changed
+5
View File
@@ -45,6 +45,11 @@ func serverStaticFiles(prefix, root string) func(next http.Handler) http.Handler
fixedPath := strings.TrimPrefix(r.URL.Path, prefix)
filePath := strings.TrimSuffix(root, "/") + "/" + strings.TrimPrefix(fixedPath, "/")
if filepath.Base(filePath) == "index.html" {
next.ServeHTTP(w, r)
return
}
slog.Debug(
"Static file request",
slog.String("path", r.URL.Path),
+3
View File
@@ -143,6 +143,9 @@ func setupRouter(router *chi.Mux, historyPoller *historyPoller) {
if config.Config.Listen.Prefix != "/" {
router.Get(getViewURL(""), redirectIndex)
}
router.Get(getViewURL("/index.html"), func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, getViewURL("/"), http.StatusMovedPermanently)
})
router.Get(getViewURL("/"), index)
router.Get(getViewURL("/version"), versionHandler)
router.Get(getViewURL("/health"), pong)
+12
View File
@@ -137,6 +137,18 @@ func TestIndex(t *testing.T) {
request: "/",
status: 200,
},
{
prefix: "",
request: "/index.html",
redirect: "/",
status: 301,
},
{
prefix: "/prefix",
request: "/prefix/index.html",
redirect: "/prefix/",
status: 301,
},
{
prefix: "",
request: "/alertList.json",