From aa710ec9d6ee5157d2ec05be760cc5237370f030 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 29 Jun 2019 15:41:44 -0700 Subject: [PATCH] Support listening for SSL connections --- wings.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wings.go b/wings.go index baba982..7019598 100644 --- a/wings.go +++ b/wings.go @@ -80,7 +80,7 @@ func main() { r := &Router{ Servers: servers, - token: c.AuthenticationToken, + token: c.AuthenticationToken, upgrader: websocket.Upgrader{ // Ensure that the websocket request is originating from the Panel itself, // and not some other location. @@ -91,9 +91,17 @@ func main() { } router := r.ConfigureRouter() - zap.S().Infow("configuring webserver", zap.String("host", c.Api.Host), zap.Int("port", c.Api.Port)) - if err := http.ListenAndServe(fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port), router); err != nil { - zap.S().Fatalw("failed to configure HTTP server", zap.Error(err)) + zap.S().Infow("configuring webserver", zap.Bool("ssl", c.Api.Ssl.Enabled), zap.String("host", c.Api.Host), zap.Int("port", c.Api.Port)) + + addr := fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port) + if c.Api.Ssl.Enabled { + if err := http.ListenAndServeTLS(addr, c.Api.Ssl.CertificateFile, c.Api.Ssl.KeyFile, router); err != nil { + zap.S().Fatalw("failed to configure HTTPS server", zap.Error(err)) + } + } else { + if err := http.ListenAndServe(addr, router); err != nil { + zap.S().Fatalw("failed to configure HTTP server", zap.Error(err)) + } } }