Serve static files
This commit is contained in:
parent
45fc4bf135
commit
448ed4805a
22
main.go
22
main.go
@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gorilla/websocket"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
@ -44,10 +46,30 @@ func main() {
|
||||
}
|
||||
nudges <- nudge
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
case "GET":
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
file, _ := os.Open("./controller/controller.html")
|
||||
defer file.Close()
|
||||
io.Copy(w, file)
|
||||
default:
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/main.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "text/css")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
file, _ := os.Open("./main.css")
|
||||
defer file.Close()
|
||||
io.Copy(w, file)
|
||||
})
|
||||
mux.HandleFunc("/controller.js", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/javascript")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
file, _ := os.Open("./controller/controller.js")
|
||||
defer file.Close()
|
||||
io.Copy(w, file)
|
||||
})
|
||||
log.Println(http.ListenAndServe(":8080", mux))
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user