Skip to content

Commit

Permalink
Add TLS support for Websocket handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Chaitanya Munukutla <[email protected]>
  • Loading branch information
c16a committed Aug 21, 2024
1 parent b2ff50f commit 357bd5c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion server/handlers/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,29 @@ import (
)

func StartWsListener(node *store.RaftNode) {
if node.Config.Ws == nil || !node.Config.Ws.Enable {
return
}

var upgrader = websocket.Upgrader{}
http.Handle("/", handleWsRequest(upgrader, node))

server := &http.Server{
Addr: node.Config.Ws.Addr,
Handler: http.DefaultServeMux,
}

tlsConfig, err := GetTlsConfig(node.Config)
if err != nil {
log.Fatal(err)
} else {
if tlsConfig != nil {
server.TLSConfig = tlsConfig
}
}

go func() {
err := http.ListenAndServe(node.Config.Ws.Addr, http.DefaultServeMux)
err := server.ListenAndServeTLS("", "")
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 357bd5c

Please sign in to comment.