From 9123e3ebffc4a52fc63800de9282d557bb84eb6e Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Mon, 25 May 2020 19:09:26 -0700 Subject: [PATCH] cli: 'kopia server' made --ui default (#452) --- cli/command_server_start.go | 4 ++-- cli/command_server_tls.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/command_server_start.go b/cli/command_server_start.go index a9b23a197..0a7749b2e 100644 --- a/cli/command_server_start.go +++ b/cli/command_server_start.go @@ -29,7 +29,7 @@ import ( var ( serverStartCommand = serverCommands.Command("start", "Start Kopia server").Default() serverStartHTMLPath = serverStartCommand.Flag("html", "Server the provided HTML at the root URL").ExistingDir() - serverStartUI = serverStartCommand.Flag("ui", "Start the server with HTML UI (EXPERIMENTAL)").Bool() + serverStartUI = serverStartCommand.Flag("ui", "Start the server with HTML UI").Default("true").Bool() serverStartRefreshInterval = serverStartCommand.Flag("refresh-interval", "Frequency for refreshing repository status").Default("10s").Duration() serverStartRandomPassword = serverStartCommand.Flag("random-password", "Generate random password and print to stderr").Hidden().Bool() @@ -138,7 +138,7 @@ func stripProtocol(addr string) string { } func isKnownUIRoute(path string) bool { - return strings.HasPrefix(path, "/snapshots/") || + return strings.HasPrefix(path, "/snapshots") || strings.HasPrefix(path, "/policies") || strings.HasPrefix(path, "/repo") } diff --git a/cli/command_server_tls.go b/cli/command_server_tls.go index db06a0bca..db1eda146 100644 --- a/cli/command_server_tls.go +++ b/cli/command_server_tls.go @@ -161,6 +161,8 @@ func startServerWithOptionalTLSAndListener(ctx context.Context, httpServer *http case *serverStartTLSCertFile != "" && *serverStartTLSKeyFile != "": // PEM files provided fmt.Fprintf(os.Stderr, "SERVER ADDRESS: https://%v\n", httpServer.Addr) + showServerUIPrompt() + return httpServer.ServeTLS(listener, *serverStartTLSCertFile, *serverStartTLSKeyFile) case *serverStartTLSGenerateCert: @@ -182,11 +184,20 @@ func startServerWithOptionalTLSAndListener(ctx context.Context, httpServer *http fingerprint := sha256.Sum256(cert.Raw) fmt.Fprintf(os.Stderr, "SERVER CERT SHA256: %v\n", hex.EncodeToString(fingerprint[:])) fmt.Fprintf(os.Stderr, "SERVER ADDRESS: https://%v\n", httpServer.Addr) + showServerUIPrompt() return httpServer.ServeTLS(listener, "", "") default: fmt.Fprintf(os.Stderr, "SERVER ADDRESS: http://%v\n", httpServer.Addr) + showServerUIPrompt() + return httpServer.Serve(listener) } } + +func showServerUIPrompt() { + if *serverStartUI { + printStderr("\nOpen the address above in a web browser to use the UI.\n") + } +}