From 7133eceb9bfa69d21d78c3afa008e67f4b2ce237 Mon Sep 17 00:00:00 2001 From: Chung-Ting Huang Date: Tue, 22 Oct 2019 10:09:59 -0500 Subject: [PATCH] TUN-2425: Enable cloudflared to serve multiple Hello World servers by having each of them create its own ServeMux --- hello/hello.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hello/hello.go b/hello/hello.go index 95d9d061..c67bb1e9 100644 --- a/hello/hello.go +++ b/hello/hello.go @@ -103,15 +103,16 @@ func StartHelloWorldServer(logger *logrus.Logger, listener net.Listener, shutdow WriteBufferSize: 1024, } - httpServer := &http.Server{Addr: listener.Addr().String(), Handler: nil} + muxer := http.NewServeMux() + muxer.HandleFunc("/uptime", uptimeHandler(time.Now())) + muxer.HandleFunc("/ws", websocketHandler(logger, upgrader)) + muxer.HandleFunc("/", rootHandler(serverName)) + httpServer := &http.Server{Addr: listener.Addr().String(), Handler: muxer} go func() { <-shutdownC httpServer.Close() }() - http.HandleFunc("/uptime", uptimeHandler(time.Now())) - http.HandleFunc("/ws", websocketHandler(logger, upgrader)) - http.HandleFunc("/", rootHandler(serverName)) err := httpServer.Serve(listener) return err }