Skip to content

Commit

Permalink
feat: add TLS support to the webconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed May 7, 2021
1 parent 9fd4ad0 commit bb2d515
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/server/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
)

func StartWebServer(addr string, s schema.ImmuServiceServer, l logger.Logger) (*http.Server, error) {
func StartWebServer(addr string, s *ImmuServer, l logger.Logger) (*http.Server, error) {
proxyMux := runtime.NewServeMux()
err := schema.RegisterImmuServiceHandlerServer(context.Background(), proxyMux, s)
if err != nil {
Expand All @@ -18,22 +18,29 @@ func StartWebServer(addr string, s schema.ImmuServiceServer, l logger.Logger) (*

webMux := http.NewServeMux()
webMux.Handle("/api/", http.StripPrefix("/api", proxyMux))
l.Infof("Web API server enabled on %s/api.", addr)

err = webconsole.SetupWebconsole(webMux, l, addr)
if err != nil {
return nil, err
}

server := &http.Server{Addr: addr, Handler: webMux}
server.TLSConfig = s.Options.TLSConfig

go func() {
if err := server.ListenAndServe(); err != nil {
if err == http.ErrServerClosed {
l.Debugf("Web API/console http server closed")
} else {
l.Errorf("Web API/console error: %s", err)
}
var err error
if s.Options.TLSConfig != nil {
l.Infof("Web API server enabled on %s/api (https)", addr)
err = server.ListenAndServeTLS("", "")
} else {
l.Infof("Web API server enabled on %s/api (http)", addr)
err = server.ListenAndServe()
}

if err == http.ErrServerClosed {
l.Debugf("Web API/console server closed")
} else {
l.Errorf("Web API/console error: %s", err)
}
}()

Expand Down

0 comments on commit bb2d515

Please sign in to comment.