Skip to content

Commit

Permalink
UI: Fix infinite redirection loop on /
Browse files Browse the repository at this point in the history
  • Loading branch information
onprem committed May 9, 2021
1 parent 3ca8084 commit 7492001
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
7 changes: 2 additions & 5 deletions pkg/ui/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ func (b *Bucket) Register(r *route.Router, registerNewUI bool, ins extpromhttp.I
// Redirect the original React UI's path (under "/new") to its new path at the root.
r.Get("/new/*path", func(w http.ResponseWriter, r *http.Request) {
p := route.Param(r.Context(), "path")
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
})

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), b.uiPrefix), http.StatusFound)
prefix := GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r)
http.Redirect(w, r, path.Join("/", prefix, p)+"?"+r.URL.RawQuery, http.StatusFound)
})

registerReactApp(r, ins, b.BaseUI)
Expand Down
8 changes: 2 additions & 6 deletions pkg/ui/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ func queryTmplFuncs() template.FuncMap {

// Register registers new GET routes for subpages and redirects from / to /graph.
func (q *Query) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/graph"), http.StatusFound)
})

r.Get("/classic/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/classic/graph"), http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/classic/graph"), http.StatusFound)
})

// Redirect the original React UI's path (under "/new") to its new path at the root.
r.Get("/new/*path", func(w http.ResponseWriter, r *http.Request) {
p := route.Param(r.Context(), "path")
http.Redirect(w, r, path.Join(GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), p)+"?"+r.URL.RawQuery, http.StatusFound)
})

r.Get("/classic/graph", instrf("graph", ins, q.graph))
Expand Down
9 changes: 2 additions & 7 deletions pkg/ui/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"path"
"regexp"
"strings"
"time"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -158,18 +157,14 @@ func (ru *Rule) rules(w http.ResponseWriter, r *http.Request) {
}

func (ru *Rule) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/alerts"), http.StatusFound)
})

r.Get("/classic/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/classic/alerts"), http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/classic/alerts"), http.StatusFound)
})

// Redirect the original React UI's path (under "/new") to its new path at the root.
r.Get("/new/*path", func(w http.ResponseWriter, r *http.Request) {
p := route.Param(r.Context(), "path")
http.Redirect(w, r, path.Join(GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), p)+"?"+r.URL.RawQuery, http.StatusFound)
})

r.Get("/classic/alerts", instrf("alerts", ins, ru.alerts))
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

var reactRouterPaths = []string{
"/",
"/alerts",
"/blocks",
"/config",
Expand Down

0 comments on commit 7492001

Please sign in to comment.