feat: add custom error page for unmatched routes

This commit is contained in:
rramiachraf 2023-01-22 16:44:22 +01:00
parent 3df6bdbf22
commit 3f5a2c5041

View File

@ -30,6 +30,14 @@ func main() {
r.HandleFunc("/{id}-lyrics", lyricsHandler) r.HandleFunc("/{id}-lyrics", lyricsHandler)
r.HandleFunc("/images/{filename}.{ext}", proxyHandler) r.HandleFunc("/images/{filename}.{ext}", proxyHandler)
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
render("error", w, map[string]string{
"Status": "404",
"Error": "page not found",
})
})
server := &http.Server{ server := &http.Server{
Handler: r, Handler: r,