Skip to content

Commit

Permalink
Merge pull request ichtrojan#20 from ichtrojan/fix-handler
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
ichtrojan authored Mar 24, 2021
2 parents 4ce5a1b + 838c56e commit 75590f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 19 additions & 1 deletion horus.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ func (config InternalConfig) Watch(next func(http.ResponseWriter, *http.Request)
log.Fatal(err)
}

ipAddress, _, _ := net.SplitHostPort(request.RemoteAddr)
ipAddress, err := getIp()

if err != nil {
ipAddress, _, _ = net.SplitHostPort(request.RemoteAddr)
}

headers, err := json.Marshal(request.Header)

Expand Down Expand Up @@ -422,3 +426,17 @@ func writer(ws *websocket.Conn) {
}
}
}

func getIp() (string, error) {
resp, err := http.Get("https://api.ipify.org?format=text")

if err != nil {
return "", errors.New("unable to get ip")
}

defer resp.Body.Close()

ip, _ := ioutil.ReadAll(resp.Body)

return string(ip), nil
}
8 changes: 7 additions & 1 deletion views/public/js/components/Horus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ module.exports = {
fetch("./logs?lastID=0")
.then((response) => response.json())
.then((data) => (this.logs = data));
let mode;
if (location.protocol != 'https:') {
mode = "ws"
}else{
mode = "wss"
}
this.connection = new WebSocket("ws://" + document.location.host + "/ws");
this.connection = new WebSocket(mode+"://" + document.location.host + "/ws");
this.connection.onclose = () => {
this.status = "disconnected";
Expand Down

0 comments on commit 75590f3

Please sign in to comment.