azer / yolo

File watcher with web UI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Websocket location.host

digibake opened this issue · comments

Hey

Thanks for making yolo, it's going to be super productive for my workflow - such great work!

To get yolo working for my use case, however, I've needed to adapt the javascript in yolo.go, line 95:

var conn = new WebSocket("ws://" + (addr[0] == ":" ? "localhost" + addr : addr) + "/socket");

// adapted to...

var conn = new WebSocket("ws://"  + location.host + "/socket");

Using 'location.host' works for me because I'm building the go code in a docker container where the internal hostname is 0.0.0.0:8080 but the port is mapped to another port (ie: http://localhost:6080)

So the original code was trying to make the websocket connect to ws://0.0.0.0:8080/socket and therefore it wasn't connecting because the page in the browser url is http://localhost:6080. If that makes sense. 'location.host' is just connecting back to the hostname in the browser so it works in a lot of use cases.

Best wishes

I somewhat got what you mean, but will need your help to create a patch for this. You can send me a PR.

The change is committed to my fork (line 97):

https://github.com/digibake/yolo/blob/master/yolo.go

I would make a pull request, but I also had to change the relative import path of that file on line 8 to
"github.com/digibake/yolo/src"
and I'm not familiar enough with golang yet, I guess that might cause a problem if you pulled it?

Yes, we can not merge that :) Why don't you send the PR pointing to this repo ? Can you also explain the potential side effects of the change in the PR ?

thx