Serve both the controller and the display on the same endpoint
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>The Fancy N</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="./main.css">
|
||||
<script src="controller.js"></script>
|
||||
<link rel="stylesheet" href="/controller/main.css">
|
||||
<script src="/controller/controller.js"></script>
|
||||
<meta name="viewport" content="width=300px, initial-scale=1">
|
||||
<style>
|
||||
body {
|
||||
|
||||
@@ -52,7 +52,7 @@ document.addEventListener("touchmove", (e) => {
|
||||
});
|
||||
|
||||
function sendNudge(x, y) {
|
||||
fetch("/", {
|
||||
fetch("", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
referrer: "no-referrer",
|
||||
|
||||
@@ -33,16 +33,9 @@ func main() {
|
||||
var clients clientsStore
|
||||
clients.set = make(map[*client]struct{})
|
||||
|
||||
go func() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Add("Access-Control-Allow-Headers", "*")
|
||||
w.Header().Add("Access-Control-Allow-Methods", "*")
|
||||
mux.HandleFunc("/controller", func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "OPTIONS":
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
case "POST":
|
||||
var nudge [2]int
|
||||
switch r.Header.Get("Content-Type") {
|
||||
@@ -79,24 +72,21 @@ func main() {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/main.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
mux.HandleFunc("/controller/main.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "text/css")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
file, _ := os.Open("./display/main.css")
|
||||
defer file.Close()
|
||||
io.Copy(w, file)
|
||||
})
|
||||
mux.HandleFunc("/controller.js", func(w http.ResponseWriter, r *http.Request) {
|
||||
mux.HandleFunc("/controller/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))
|
||||
}()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", http.FileServer(http.Dir("./display/")))
|
||||
mux.HandleFunc("/socket", func(w http.ResponseWriter, r *http.Request) {
|
||||
con, err := upgrader.Upgrade(w, r, nil)
|
||||
@@ -130,5 +120,5 @@ func main() {
|
||||
}
|
||||
}
|
||||
})
|
||||
log.Println(http.ListenAndServe(":8081", mux))
|
||||
log.Println(http.ListenAndServe(":8080", mux))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user