Skip to content

Commit

Permalink
Redirect over routePrefix on non-matching path
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Nebel <[email protected]>
  • Loading branch information
snebel29 committed Sep 8, 2019
1 parent d268388 commit 2afe4f0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func run() int {
*routePrefix = beURL.Path
}

// RoutePrefix must always be at least '/'.
// routePrefix must always be at least '/'.
*routePrefix = "/" + strings.Trim(*routePrefix, "/")
level.Debug(logger).Log("routePrefix", *routePrefix)

Expand Down Expand Up @@ -345,6 +345,11 @@ func run() int {
w.Write(c)
})

// Redirect over routePrefix for any other path
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, *routePrefix, http.StatusFound)
})

srv := http.Server{Addr: *listenAddress}
srvc := make(chan struct{})
term := make(chan os.Signal, 1)
Expand Down

0 comments on commit 2afe4f0

Please sign in to comment.