fixed router.ServeHTTP

added in middleware: Cors and Helmet
This commit is contained in:
2024-11-03 15:33:50 +05:30
parent 116afe7930
commit f72529aea5
5 changed files with 738 additions and 1 deletions

View File

@@ -141,7 +141,16 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
panic("mux: method ServeHTTP called on nil")
}
r.mux.ServeHTTP(w, req)
h, pattern := r.mux.Handler(req)
if pattern == "" {
http.Error(w, "Not Found", http.StatusNotFound)
return
}
// ensure we run all the middlewares
h = stack(r.middlewares, h)
// serve
h.ServeHTTP(w, req)
}
// stack middlewares(http handler) in order they are passed (FIFO)