aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authormyOmikron <git@omikron.dev>2023-01-25 21:47:29 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-02-24 12:47:40 +0100
commit500475141ce02f85812bfacbc3528606eab9a5e0 (patch)
tree71cade20a335aab13b444e76fd8a45e1b91d3570 /main.go
parentc0c4bea988208f75fa4534b807a026de3f619eaf (diff)
downloadWRMS-500475141ce02f85812bfacbc3528606eab9a5e0.tar.gz
WRMS-500475141ce02f85812bfacbc3528606eab9a5e0.zip
Moved endpoints
Diffstat (limited to 'main.go')
-rw-r--r--main.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/main.go b/main.go
index ccce08b..22e0e08 100644
--- a/main.go
+++ b/main.go
@@ -17,12 +17,14 @@ import (
var wrms *Wrms
-func landingPage(w http.ResponseWriter, r *http.Request) {
+func retrieveCookie(w http.ResponseWriter, r *http.Request) {
if _, err := r.Cookie("UUID"); err != nil {
- http.SetCookie(w, &http.Cookie{Name: "UUID", Value: uuid.NewString(), Path: "/",})
+ http.SetCookie(w, &http.Cookie{Name: "UUID", Value: uuid.NewString(), Path: "/"})
}
http.Redirect(w, r, "/static/index.html", http.StatusSeeOther)
+
+ w.WriteHeader(http.StatusNoContent)
}
func searchHandler(w http.ResponseWriter, r *http.Request) {
@@ -194,7 +196,7 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) {
}
func setupRoutes() {
- http.HandleFunc("/", landingPage)
+ http.HandleFunc("/cookie", retrieveCookie)
http.HandleFunc("/search", searchHandler)
http.HandleFunc("/up", upHandler)
http.HandleFunc("/down", downHandler)
@@ -202,7 +204,7 @@ func setupRoutes() {
http.HandleFunc("/add", addHandler)
http.HandleFunc("/playpause", playPauseHandler)
http.HandleFunc("/ws", wsEndpoint)
- http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("./web/build"))))
+ http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./web/dist"))))
}
func main() {
@@ -223,6 +225,7 @@ func main() {
// wrms.AddSong(NewDummySong("Lala", "SNFMT"))
// wrms.AddSong(NewDummySong("Hobelbank", "MC Wankwichtel"))
+ fmt.Printf("Listening on http://0.0.0.0:%d\n", config.port)
err := http.ListenAndServe(fmt.Sprintf(":%d", config.port), nil)
llog.Error("Serving http failed with %s", err)
}