Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Kelp GUI: fix TLS changes added in 5c36ead
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf committed Apr 15, 2021
1 parent 8b64485 commit 345f680
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
6 changes: 1 addition & 5 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,9 @@ func init() {
gui.FileServer(r, "/", gui.FS)

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{}) {
e1 := webServer.StartServer(*options.port, *options.tlsCertFile, *options.tlsKeyFile)
e1 := networking.StartServer(r, *options.port, *options.tlsCertFile, *options.tlsKeyFile)
if e1 != nil {
log.Fatal(e1)
}
Expand Down
16 changes: 8 additions & 8 deletions support/networking/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ type server struct {
permittedEmails map[string]bool
}

// 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)
Expand Down Expand Up @@ -73,10 +68,15 @@ func MakeServerWithGoogleAuth(cfg *Config, endpoints []Endpoint) (WebServer, err
return s, nil
}

// StartServer starts the server by using the router on the server struct
func (s *server) StartServer(port uint16, certFile string, keyFile string) error {
return StartServer(s.router, port, certFile, keyFile)
}

// StartServer starts the monitoring server by listening on the specified port and serving requests
// according to its handlers. If certFile and keyFile aren't empty, then the server will use TLS.
// This call will block or return a non-nil error.
func (s *server) StartServer(port uint16, certFile string, keyFile string) error {
func StartServer(handler http.Handler, port uint16, certFile string, keyFile string) error {
addr := ":" + strconv.Itoa(int(port))
if certFile != "" && keyFile != "" {
_, e := os.Stat(certFile)
Expand All @@ -87,9 +87,9 @@ func (s *server) StartServer(port uint16, certFile string, keyFile string) error
if e != nil {
return fmt.Errorf("provided tls key file cannot be found")
}
return http.ListenAndServeTLS(addr, certFile, keyFile, s.router)
return http.ListenAndServeTLS(addr, certFile, keyFile, handler)
}
return http.ListenAndServe(addr, s.router)
return http.ListenAndServe(addr, handler)
}

// googleAuthHandler creates a random key to encrypt/decrypt session cookies
Expand Down

0 comments on commit 345f680

Please sign in to comment.