From df80493dd9edf0d7727677a12b23a3def5809925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 14 Aug 2026 11:39:59 +0100 Subject: [PATCH] fix(backend): redirect index.html to / Fixes #7069 --- CHANGELOG.md | 6 ++++++ cmd/karma/assets.go | 5 +++++ cmd/karma/main.go | 3 +++ cmd/karma/views_test.go | 12 ++++++++++++ 4 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc74110f..73c43c22f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.133 + +### Changed + +- Requests for `/index.html` will now be redirected to `/` - #7069. + ## v0.132 ### Changed diff --git a/cmd/karma/assets.go b/cmd/karma/assets.go index 7dbde412d..3fd090149 100644 --- a/cmd/karma/assets.go +++ b/cmd/karma/assets.go @@ -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), diff --git a/cmd/karma/main.go b/cmd/karma/main.go index b100f97e3..364e54693 100644 --- a/cmd/karma/main.go +++ b/cmd/karma/main.go @@ -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) diff --git a/cmd/karma/views_test.go b/cmd/karma/views_test.go index 1ac6f1cc1..70131c97a 100644 --- a/cmd/karma/views_test.go +++ b/cmd/karma/views_test.go @@ -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",