@@ -48,28 +48,30 @@ func NewBucketUI(logger log.Logger, label, externalPrefix, prefixHeader, uiPrefi
48
48
}
49
49
50
50
// Register registers http routes for bucket UI.
51
- func (b * Bucket ) Register (r * route.Router , registerNewUI bool , ins extpromhttp.InstrumentationMiddleware ) {
52
- instrf := func (name string , next func (w http.ResponseWriter , r * http.Request )) http.HandlerFunc {
53
- return ins .NewHandler (b .externalPrefix + name , http .HandlerFunc (next ))
54
- }
55
- r .WithPrefix (b .uiPrefix ).Get ("/" , instrf ("root" , b .root ))
56
- r .WithPrefix (b .uiPrefix ).Get ("/static/*filepath" , instrf ("static" , b .serveStaticAsset ))
57
- if registerNewUI {
58
- // Make sure that "<path-prefix>/new" is redirected to "<path-prefix>/new/" and
59
- // not just the naked "/new/", which would be the default behavior of the router
60
- // with the "RedirectTrailingSlash" option (https://godoc.org/github.com/julienschmidt/httprouter#Router.RedirectTrailingSlash),
61
- // and which breaks users with a --web.route-prefix that deviates from the path derived
62
- // from the external URL.
63
- r .Get ("/new" , func (w http.ResponseWriter , r * http.Request ) {
64
- http .Redirect (w , r , path .Join (GetWebPrefix (b .logger , b .externalPrefix , b .prefixHeader , r ), "new" )+ "/" , http .StatusFound )
65
- })
66
- r .Get ("/new/*filepath" , instrf ("react-static" , b .serveReactUI ))
51
+ func (b * Bucket ) Register (r * route.Router , ins extpromhttp.InstrumentationMiddleware ) {
52
+ redirectPath := "/blocks"
53
+ if len (b .uiPrefix ) > 0 {
54
+ redirectPath = b .uiPrefix
67
55
}
56
+ r .Get ("/" , func (w http.ResponseWriter , r * http.Request ) {
57
+ http .Redirect (w , r , path .Join (GetWebPrefix (b .logger , b .externalPrefix , b .prefixHeader , r ), redirectPath ), http .StatusFound )
58
+ })
59
+ // Redirect the original React UI's path (under "/new") to its new path at the root.
60
+ r .Get ("/new/*path" , func (w http.ResponseWriter , r * http.Request ) {
61
+ p := route .Param (r .Context (), "path" )
62
+ http .Redirect (w , r , path .Join (GetWebPrefix (b .logger , b .externalPrefix , b .prefixHeader , r ), strings .TrimPrefix (p , "/new" ))+ "?" + r .URL .RawQuery , http .StatusFound )
63
+ })
64
+
65
+ r .Get (path .Join ("/classic" , b .uiPrefix ), instrf ("bucket" , ins , b .bucket ))
66
+ r .WithPrefix (b .uiPrefix ).Get ("/classic/static/*filepath" , instrf ("static" , ins , b .serveStaticAsset ))
67
+ registerReactApp (r , ins , b .BaseUI )
68
68
}
69
69
70
70
// Handle / of bucket UIs.
71
- func (b * Bucket ) root (w http.ResponseWriter , r * http.Request ) {
72
- b .executeTemplate (w , "bucket.html" , GetWebPrefix (b .logger , path .Join (b .externalPrefix , strings .TrimPrefix (b .uiPrefix , "/" )), b .prefixHeader , r ), b )
71
+ func (b * Bucket ) bucket (w http.ResponseWriter , r * http.Request ) {
72
+ prefix := GetWebPrefix (b .logger , path .Join (b .externalPrefix , strings .TrimPrefix (b .uiPrefix , "/" )), b .prefixHeader , r )
73
+ b .logger .Log (prefix )
74
+ b .executeTemplate (w , "bucket.html" , prefix , b )
73
75
}
74
76
75
77
func (b * Bucket ) Set (blocks []metadata.Meta , err error ) {
0 commit comments