From 85dbada468b76cec6a6b143ccd44b817d8a51e78 Mon Sep 17 00:00:00 2001 From: Robert Kesterson Date: Tue, 23 May 2023 13:59:10 -0400 Subject: [PATCH] Allow operator console to be hosted at subpath Signed-off-by: Robert Kesterson --- api/configure_operator.go | 7 ++++--- docs/env-variables.md | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/configure_operator.go b/api/configure_operator.go index 1f047711c5b..a7a21a02e2d 100644 --- a/api/configure_operator.go +++ b/api/configure_operator.go @@ -315,7 +315,7 @@ func replaceBaseInIndex(indexPageBytes []byte, basePath string) []byte { // handleSPA handles the serving of the React Single Page Application func handleSPA(w http.ResponseWriter, r *http.Request) { - basePath := "/" + basePath := getSubPath() // For SPA mode we will replace root base with a sub path if configured unless we received cp=y and cpb=/NEW/BASE if v := r.URL.Query().Get("cp"); v == "y" { if base := r.URL.Query().Get("cpb"); base != "" { @@ -363,7 +363,7 @@ func handleSPA(w http.ResponseWriter, r *http.Request) { // wrapHandlerSinglePageApplication handles a http.FileServer returning a 404 and overrides it with index.html func wrapHandlerSinglePageApplication(h http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/" { + if match, _ := regexp.MatchString(fmt.Sprintf("^%s/?$", getSubPath()), r.URL.Path); match { handleSPA(w, r) return } @@ -381,8 +381,9 @@ func wrapHandlerSinglePageApplication(h http.Handler) http.HandlerFunc { func FileServerMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", globalAppName) // do not add version information + basePath := getSubPath() switch { - case strings.HasPrefix(r.URL.Path, "/api"): + case strings.HasPrefix(r.URL.Path, basePath+"/api"): next.ServeHTTP(w, r) default: buildFs, err := fs.Sub(webApp.GetStaticAssets(), "build") diff --git a/docs/env-variables.md b/docs/env-variables.md index f959c0fb7f7..81d7d452241 100644 --- a/docs/env-variables.md +++ b/docs/env-variables.md @@ -13,4 +13,5 @@ Operator behavior can be customized using environment variables in the `minio-op |OPERATOR_STS_ENABLED| This toggles the STS Service on or off | `on`, `off` | `off` | |MINIO_CONSOLE_DEPLOYMENT_NAME| This is the default name of the console deployment | | `console` | |MINIO_CONSOLE_TLS_ENABLE| This toggles the Console TLS on or off | `on`, `off` | `off` | -|WATCHED_NAMESPACE| The namespaces which the operator watches for MinIO tenants. Defaults to `""` for all namespaces. | | | +|WATCHED_NAMESPACE| The namespaces which the operator watches for MinIO tenants. Defaults to `""` for all namespaces. +|OPERATOR_SUBPATH| the subpath that the operator console is served from.