Remove SSL, serve static index.html

This commit is contained in:
Josh Grebe 2020-01-25 17:44:29 -05:00
parent e5c38a85a8
commit c71ce9fc2e
2 changed files with 11 additions and 2 deletions

View File

@ -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);

11
main.go
View File

@ -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)