diff --git a/database.sqlite3 b/database.sqlite3 index 0baa834..6310295 100644 Binary files a/database.sqlite3 and b/database.sqlite3 differ 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) + })) }