koding / websocketproxy

WebSocket reverse proxy handler for Go
http://godoc.org/github.com/koding/websocketproxy
MIT License
427 stars 120 forks source link

couldn't upgrade websocket #41

Closed ardawan closed 3 years ago

ardawan commented 3 years ago

I'm using it on my local machine and servers are separated by docker.

I'm getting errors from the websocketproxy.

this is the log

==> message/logs/2021-05-06.txt <==
2021/05/06 08:50:07 **** JOIN

==> gateway/logs/2021-05-06.txt <==
2021/05/06 08:50:07 websocketproxy: couldn't upgrade websocket: request origin not allowed by Upgrader.CheckOrigin

==> message/logs/2021-05-06.txt <==
2021/05/06 08:50:07 websocket: close 1006 (abnormal closure): unexpected EOF

proxy router

r.HandleFunc("/ws/{token}", func(w http.ResponseWriter, res *http.Request) {
// target                                                                              
params := mux.Vars(res) 
url, _ := url.Parse("ws://14.14.0.1:7039/ws/" + params["token"])
proxy := websocketproxy.NewProxy(url)
proxy.ServeHTTP(w, res)
}
kevinbarabash commented 2 years ago

I ran into the same issue as well. I was able to fix it by making the following tweak to the source code:

    upgrader.CheckOrigin = func(r *http.Request) bool {
        // Allow any origin to connect
        return true
    }