Handle CORS errors in gorilla websockets

TLD(W)R; // Allow everyone var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, } // Allow a specific domain var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { origin := r.Header.Get("Origin") return origin == "https://your.domain.com" }, } ...

December 11, 2024 · 4 min