From 9f3301f965b23d24c90d494fa4315f56adaab75d Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sat, 14 Nov 2020 15:19:50 +0100 Subject: [PATCH] Almost there --- server.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index fdc3659..6e4347d 100644 --- a/server.go +++ b/server.go @@ -13,11 +13,11 @@ import ( "time" ) -const ROOT_URL = "/climate/" +const ROOT_URL = "/climate" func startServer() { port := "8001" - router := mux.NewRouter().StrictSlash(true) + router := mux.NewRouter() router.HandleFunc("/show", showCharts).Methods("GET") router.HandleFunc("/show", showCharts).Methods("GET").Queries("show-minutes", "{[0-9]+}") router.HandleFunc("/data", sendData).Methods("GET") @@ -33,12 +33,12 @@ func showCharts(w http.ResponseWriter, r *http.Request) { minutes := r.FormValue("show-minutes") if minutes != "" { if _, err := strconv.ParseInt(minutes, 10, 0); err != nil { - http.Redirect(w, r, ROOT_URL, 303) + http.Redirect(w, r, ROOT_URL + "/show", 303) } } templater, err := template.ParseFiles("webapp/dist/charts.html") if internalErrorOnErr(fmt.Errorf("couldn't parse the template: %w", err), w, r) { return } - err = templater.Execute(w, ROOT_URL) + err = templater.Execute(w, ROOT_URL + "/show") internalErrorOnErr(err, w, r) } @@ -48,7 +48,7 @@ func sendData(w http.ResponseWriter, r *http.Request) { if sinceQuery != "" { newDateSince, err := time.Parse(time.RFC3339Nano, sinceQuery) if err != nil { - http.Redirect(w, r, ROOT_URL, 303) + http.Redirect(w, r, ROOT_URL + "/show", 303) return } dateSince = strings.Split(newDateSince.Format(time.RFC3339Nano), "Z")[0]