enforce get on index

master
Jason Staten 2 years ago
parent d9b95ef24e
commit e68d59a48f

@ -145,7 +145,7 @@ func (s *server) HandleClear() http.HandlerFunc {
func (s *server) routes() {
s.router.Handle("/public/", http.FileServer(http.FS(publicFS)))
s.router.HandleFunc("/", s.HandleList())
s.router.HandleFunc("/", WithMethod("GET", s.HandleList()))
s.router.HandleFunc("/todo", WithForm(WithMethod("POST", s.HandleCreate())))
s.router.HandleFunc("/toggle", WithForm(WithMethod("POST", s.HandleToggle())))
s.router.HandleFunc("/destroy", WithForm(WithMethod("POST", s.HandleDestroy())))

@ -6,6 +6,7 @@ func WithMethod(method string, next http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != method {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Method Not Allowed"))
return
}
next.ServeHTTP(w, r)

Loading…
Cancel
Save