diff --git a/cmd/server_amd64.go b/cmd/server_amd64.go index 454abd7fa..259a08aed 100644 --- a/cmd/server_amd64.go +++ b/cmd/server_amd64.go @@ -69,6 +69,8 @@ type serverInputOptions struct { noElectron *bool disablePubnet *bool enableKaas *bool + tlsCertFile *string + tlsKeyFile *string } // String is the stringer method impl. @@ -89,6 +91,8 @@ func init() { options.noElectron = serverCmd.Flags().Bool("no-electron", false, "open in browser instead of using electron, only applies when not in KaaS mode") options.disablePubnet = serverCmd.Flags().Bool("disable-pubnet", false, "disable pubnet option") options.enableKaas = serverCmd.Flags().Bool("enable-kaas", false, "enable kelp-as-a-service (KaaS) mode, which does not bring up browser or electron") + options.tlsCertFile = serverCmd.Flags().String("tls-cert-file", "", "path to TLS certificate file") + options.tlsKeyFile = serverCmd.Flags().String("tls-key-file", "", "path to TLS key file") serverCmd.Run = func(ccmd *cobra.Command, args []string) { isLocalMode := env == envDev @@ -404,21 +408,16 @@ func init() { // gui.FS is automatically compiled based on whether this is a local or deployment build gui.FileServer(r, "/", gui.FS) - portString := fmt.Sprintf(":%d", *options.port) log.Printf("starting server on port %d\n", *options.port) - + webServer, e := networking.MakeServer() + if e != nil { + log.Fatal(e) + } threadTracker := multithreading.MakeThreadTracker() e = threadTracker.TriggerGoroutine(func(inputs []interface{}) { - if isLocalMode { - e1 := http.ListenAndServe(portString, r) - if e1 != nil { - log.Fatal(e1) - } - } else { - e1 := http.ListenAndServe(portString, r) - if e1 != nil { - log.Fatal(e1) - } + e1 := webServer.StartServer(*options.port, *options.tlsCertFile, *options.tlsKeyFile) + if e1 != nil { + log.Fatal(e1) } }, nil) if e != nil { diff --git a/cmd/trade.go b/cmd/trade.go index 0fa814b04..be06ed6cc 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -873,7 +873,7 @@ func startMonitoringServer(l logger.Logger, botConfig trader.BotConfig) error { for _, email := range strings.Split(botConfig.AcceptableEmails, ",") { serverConfig.PermittedEmails[email] = true } - server, e := networking.MakeServer(serverConfig, []networking.Endpoint{healthEndpoint, metricsEndpoint}) + server, e := networking.MakeServerWithGoogleAuth(serverConfig, []networking.Endpoint{healthEndpoint, metricsEndpoint}) if e != nil { return fmt.Errorf("unable to initialize the metrics server: %s", e) } diff --git a/support/networking/server.go b/support/networking/server.go index 96dfa8d48..0b96d2d46 100644 --- a/support/networking/server.go +++ b/support/networking/server.go @@ -39,8 +39,13 @@ type server struct { permittedEmails map[string]bool } -// MakeServer creates a WebServer that's responsible for serving all the endpoints passed into it. -func MakeServer(cfg *Config, endpoints []Endpoint) (WebServer, error) { +// MakeServer creates a WebServer +func MakeServer() (WebServer, error) { + return MakeServerWithGoogleAuth(&Config{}, []Endpoint{}) +} + +// MakeServerWithGoogleAuth creates a WebServer that's responsible for serving all the endpoints passed into it with google authentication. +func MakeServerWithGoogleAuth(cfg *Config, endpoints []Endpoint) (WebServer, error) { mux := new(http.ServeMux) s := &server{ router: mux,