diff --git a/cmd/common-main.go b/cmd/common-main.go index 116f4d34e..45a4e90d9 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -114,13 +114,16 @@ func minioConfigToConsoleFeatures() { os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0]) if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" { os.Setenv("CONSOLE_LOG_QUERY_URL", value) - } - if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" { - os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value) + if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" { + os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value) + } } // Enable if prometheus URL is set. if value := env.Get("MINIO_PROMETHEUS_URL", ""); value != "" { os.Setenv("CONSOLE_PROMETHEUS_URL", value) + if value := env.Get("MINIO_PROMETHEUS_JOB_ID", "minio-job"); value != "" { + os.Setenv("CONSOLE_PROMETHEUS_JOB_ID", value) + } } // Enable if LDAP is enabled. if globalLDAPConfig.Enabled { @@ -413,11 +416,6 @@ func handleCommonEnvVars() { logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER value in environment variable") } - globalBrowserRedirect, err = config.ParseBool(env.Get(config.EnvBrowserRedirect, config.EnableOn)) - if err != nil { - logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER_REDIRECT value in environment variable") - } - globalFSOSync, err = config.ParseBool(env.Get(config.EnvFSOSync, config.EnableOff)) if err != nil { logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable") diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index 1c92db230..b7bf21e09 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -22,6 +22,7 @@ import ( "net" "net/http" "net/url" + "path" "strings" "sync/atomic" "time" @@ -161,10 +162,9 @@ func guessIsBrowserReq(r *http.Request) bool { func setBrowserRedirectHandler(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Re-direction is handled specifically for browser requests. - if guessIsBrowserReq(r) && globalBrowserRedirect { + if guessIsBrowserReq(r) { // Fetch the redirect location if any. - u := getRedirectLocation(r) - if u != nil { + if u := getRedirectLocation(r); u != nil { // Employ a temporary re-direct. http.Redirect(w, r, u.String(), http.StatusTemporaryRedirect) return @@ -184,33 +184,36 @@ func shouldProxy() bool { // serves only limited purpose on redirect-handler for // browser requests. func getRedirectLocation(r *http.Request) *url.URL { - hostname, _, _ := net.SplitHostPort(r.Host) - if hostname == "" { - hostname = r.Host + resource, err := getResource(r.URL.Path, r.Host, globalDomainNames) + if err != nil { + return nil } - var rurl = &url.URL{ - Host: net.JoinHostPort(hostname, globalMinioConsolePort), + for _, prefix := range []string{ + "favicon-16x16.png", + "favicon-32x32.png", + "favicon-96x96.png", + "index.html", + minioReservedBucket, + } { + bucket, _ := path2BucketObject(resource) + if path.Clean(bucket) == prefix || resource == slashSeparator { + hostname, _, _ := net.SplitHostPort(r.Host) + if hostname == "" { + hostname = r.Host + } + return &url.URL{ + Host: net.JoinHostPort(hostname, globalMinioConsolePort), + Scheme: func() string { + scheme := "http" + if r.TLS != nil { + scheme = "https" + } + return scheme + }(), + } + } } - urlPath := r.URL.Path - scheme := "http" - if r.TLS != nil { - scheme = "https" - } - rurl.Scheme = scheme - if urlPath == minioReservedBucketPath { - rurl.Path = minioReservedBucketPath + SlashSeparator - } - if contains([]string{ - SlashSeparator, - "/webrpc", - "/login", - "/favicon-16x16.png", - "/favicon-32x32.png", - "/favicon-96x96.png", - }, urlPath) { - rurl.Path = minioReservedBucketPath + urlPath - } - return rurl + return nil } // guessIsHealthCheckReq - returns true if incoming request looks diff --git a/cmd/globals.go b/cmd/globals.go index 591875b80..954943c91 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -137,9 +137,6 @@ var ( // This flag is set to 'true' by default globalBrowserEnabled = true - // This flag is set to 'true' by default. - globalBrowserRedirect = true - // This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false. globalInplaceUpdateDisabled = false diff --git a/internal/config/constants.go b/internal/config/constants.go index 2331a8914..911d256ee 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -29,14 +29,13 @@ const ( EnvRootUser = "MINIO_ROOT_USER" EnvRootPassword = "MINIO_ROOT_PASSWORD" - EnvBrowser = "MINIO_BROWSER" - EnvBrowserRedirect = "MINIO_BROWSER_REDIRECT" - EnvDomain = "MINIO_DOMAIN" - EnvRegionName = "MINIO_REGION_NAME" - EnvPublicIPs = "MINIO_PUBLIC_IPS" - EnvFSOSync = "MINIO_FS_OSYNC" - EnvArgs = "MINIO_ARGS" - EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT" + EnvBrowser = "MINIO_BROWSER" + EnvDomain = "MINIO_DOMAIN" + EnvRegionName = "MINIO_REGION_NAME" + EnvPublicIPs = "MINIO_PUBLIC_IPS" + EnvFSOSync = "MINIO_FS_OSYNC" + EnvArgs = "MINIO_ARGS" + EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT" EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE"