From c71ce9fc2e00cde5daac08c4c17c7f11998343f2 Mon Sep 17 00:00:00 2001 From: Josh Grebe Date: Sat, 25 Jan 2020 17:44:29 -0500 Subject: [PATCH] Remove SSL, serve static index.html --- index.html | 2 +- main.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 2ded946..ab5ccf0 100644 --- a/index.html +++ b/index.html @@ -120,7 +120,7 @@ this.psi.set(0); // set actual value // Set up websocket connection - this.sock = new WebSocket("wss://" + window.location.hostname + "/ws/"); + this.sock = new WebSocket("ws://" + window.location.hostname + ":9888/ws/"); this.sock.addEventListener('open', this.gotWsOpen ); this.sock.addEventListener('message', this.gotWsMessage); this.sock.addEventListener('error', this.gotWsError); diff --git a/main.go b/main.go index ac4ccc9..a5e68c0 100644 --- a/main.go +++ b/main.go @@ -49,9 +49,18 @@ var upgrader = websocket.Upgrader{ } func main() { - http.HandleFunc("/ws", subscribe) + http.HandleFunc("/ws/", subscribe) + http.HandleFunc("/", serveIndex) log.Fatal(http.ListenAndServe("localhost:9888", nil)) } +func serveIndex(w http.ResponseWriter, r *http.Request) { + f, err := os.Open("index.html") + if err != nil { + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } + io.Copy(w, f) +} func subscribe(w http.ResponseWriter, r *http.Request) { c, err := upgrader.Upgrade(w, r, nil)