From 2a30d8f0ff71ed3833cc45d950379e37b57a4bc5 Mon Sep 17 00:00:00 2001 From: bytedream Date: Mon, 31 Jan 2022 12:47:06 +0100 Subject: [PATCH] Added admin admin test user --- database.sqlite3 | Bin 65536 -> 65536 bytes main.go | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/database.sqlite3 b/database.sqlite3 index 0baa834508ba9d04f76386ca355901eb5a8523a3..63102955c43dd000a98711d9b2ab078b91f9e811 100644 GIT binary patch delta 170 zcmZo@U}6lWl5-^d$zNFVY*+rv0-VrzhR1TMyZL1Ws#d#fWDbuPO`Ue zV3m8GXO>4=Sf+))Bgg=S{4|A%KGaf8Q+V@Rpy8gISyt SY!&Zj#sKDo%`6Z8$O8b7S2eHz delta 44 zcmV+{0Mq|~fCPYm1dtm6;gK9e0pYP=jV}QRv+gez5VHi3{4cVg1VEz%P$07e(EKlP C77+yi diff --git a/main.go b/main.go index 76d825a..b5d6253 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "github.com/gorilla/mux" "html/template" "net/http" - "path" "path/filepath" ) @@ -50,6 +49,13 @@ func setupApi(r *mux.Router) { r.HandleFunc("/api/article", api.Article).Methods(http.MethodPost, http.MethodPatch, http.MethodDelete) r.HandleFunc("/api/assets", api.Assets).Methods(http.MethodGet, http.MethodPost, http.MethodDelete) + + r.MethodNotAllowedHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + api.ApiError{Message: "invalid method", Code: http.StatusNotFound}.Send(w) + })) + r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + api.ApiError{Message: "invalid endpoint", Code: http.StatusNotFound}.Send(w) + })) } func setupFrontend(r *mux.Router) { @@ -60,12 +66,11 @@ func setupFrontend(r *mux.Router) { r.PathPrefix("/js/").HandlerFunc(server.ServePath) landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml"))) - - r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if path.Join(config.Prefix)+"/" == r.URL.Path { - landingpage.Execute(w, config.PageBase) - } else { - server.Error404(w, r) - } + r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + landingpage.Execute(w, config.PageBase) }) + + r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + server.Error404(w, r) + })) }