feat: add custom error page for unmatched routes
This commit is contained in:
parent
3df6bdbf22
commit
3f5a2c5041
8
main.go
8
main.go
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user