From f5799ca299f0598d3326b591342f073c92399420 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 25 Apr 2023 09:32:32 +0800 Subject: [PATCH 1/3] Make both `/ui/?query=` and `/ui?query=` work --- pkg/api/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index de27117b7..726bd600c 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -146,7 +146,7 @@ func (a *API) RegisterAPI(statusService statusv1.StatusServiceServer) error { // All assets are served as static files a.RegisterRoutesWithPrefix("/ui/assets/", http.StripPrefix("/ui/", http.FileServer(uiAssets)), false, true, "GET") // Serve index to all other pages - a.RegisterRoutesWithPrefix("/ui/", uiIndexHandler, false, true, "GET") + a.RegisterRoutesWithPrefix("/ui", uiIndexHandler, false, true, "GET") // register status service providing config and buildinfo at grpc gateway if err := statusv1.RegisterStatusServiceHandlerServer(context.Background(), a.grpcGatewayMux, statusService); err != nil { From 1c48fd27691b1073343d510266421b6395cd00c4 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 27 Apr 2023 10:24:55 +0800 Subject: [PATCH 2/3] Add redirection --- pkg/api/api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 726bd600c..236edeb52 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -146,7 +146,10 @@ func (a *API) RegisterAPI(statusService statusv1.StatusServiceServer) error { // All assets are served as static files a.RegisterRoutesWithPrefix("/ui/assets/", http.StripPrefix("/ui/", http.FileServer(uiAssets)), false, true, "GET") // Serve index to all other pages - a.RegisterRoutesWithPrefix("/ui", uiIndexHandler, false, true, "GET") + a.RegisterRoutesWithPrefix("/ui/", uiIndexHandler, false, true, "GET") + // Redirect `/ui` to `/ui/`. + // See more: https://github.com/grafana/phlare/pull/649#issuecomment-1522958157. + a.RegisterRoute("/ui", http.RedirectHandler("/ui/", http.StatusMovedPermanently), false, true, "GET") // register status service providing config and buildinfo at grpc gateway if err := statusv1.RegisterStatusServiceHandlerServer(context.Background(), a.grpcGatewayMux, statusService); err != nil { From 4748a38eb71817d6d770791caa7eb22f0b2cf232 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 27 Apr 2023 20:57:39 +0800 Subject: [PATCH 3/3] Address comment --- pkg/api/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 236edeb52..cecf0401b 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -149,7 +149,7 @@ func (a *API) RegisterAPI(statusService statusv1.StatusServiceServer) error { a.RegisterRoutesWithPrefix("/ui/", uiIndexHandler, false, true, "GET") // Redirect `/ui` to `/ui/`. // See more: https://github.com/grafana/phlare/pull/649#issuecomment-1522958157. - a.RegisterRoute("/ui", http.RedirectHandler("/ui/", http.StatusMovedPermanently), false, true, "GET") + a.RegisterRoute("/ui", http.RedirectHandler("/ui/", http.StatusFound), false, true, "GET") // register status service providing config and buildinfo at grpc gateway if err := statusv1.RegisterStatusServiceHandlerServer(context.Background(), a.grpcGatewayMux, statusService); err != nil {