commit 5b01df903085fbba96e52277e598c395bce27d88 Author: David Fifield david@bamsoftware.com Date: Tue Jan 28 00:09:38 2020 -0700
Initialize the global upgrader.CheckOrigin statically.
Only once, not again on every call to initServer. --- server/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/server/server.go b/server/server.go index 9023252..acb260a 100644 --- a/server/server.go +++ b/server/server.go @@ -94,7 +94,9 @@ func clientAddr(clientIPParam string) string { return (&net.TCPAddr{IP: clientIP, Port: 1, Zone: ""}).String() }
-var upgrader = websocket.Upgrader{} +var upgrader = websocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { return true }, +}
type HTTPHandler struct{}
@@ -139,8 +141,6 @@ func initServer(addr *net.TCPAddr, return nil, fmt.Errorf("cannot listen on port %d; configure a port using ServerTransportListenAddr", addr.Port) }
- upgrader.CheckOrigin = func(r *http.Request) bool { return true } - var handler HTTPHandler server := &http.Server{ Addr: addr.String(),