I lower and pasted a pattern code from right here This code works out of the field on my native laptop.
However when shifting to a VPS with Nginx proxy this fails. As this “converts” from https:// to wss:// I’ve no clue what I’ve completed mistaken. https://ws.go4webdev.org (reside)
The console provides this error:
WebSocket connection to ‘wss://localhost:8080/echo’ failed:
And the web page exhibits up like this:
I believe that it’s this line that’s the drawback, however I can not work out the syntax.
//var addr = flag.String("addr", "127.0.0.1:8080", "http service tackle") <-- works on my native laptop
var addr = flag.String("addr", "https://ws.go4webdev.org", "http service tackle") <-- fails on VPS
My intestine feeling tells me that that is near a CORS error, however I can not affirm.
Any clue how I could make this work?
The reply lies in your template:
homeTemplate.Execute(w, "ws://"+r.Host+"/echo")
Are you operating this behind a reverse proxy or one thing? A easy repair could be to eliminate that a part of the template and as a substitute push the logic to the browser. One thing like this:
ws = new WebSocket("ws://" + doc.location.host + "/echo");