Add 404 page

main
Elnu 2 years ago
parent 33ecd1a539
commit dee29d1277

@ -431,6 +431,20 @@ func main() {
}, },
[]string{http.MethodGet}, []string{http.MethodGet},
)) ))
r.PathPrefix("/").Handler(http.FileServer(http.Dir("static"))) r.NotFoundHandler = http.HandlerFunc(httputils.GenerateHandler(
func(w http.ResponseWriter, r *http.Request) bool { return true },
httputils.NewTemplateSet("index.html", "404.html"),
func(w http.ResponseWriter, r *http.Request) (template string, data any) {
w.WriteHeader(http.StatusNotFound)
return "404.html", nil
},
[]string{http.MethodGet},
))
r.Path("/logo.svg").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/logo.svg")
}))
r.Path("/overrides.css").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/overrides.css")
}))
log.Fatal(http.ListenAndServe(":3334", r)) log.Fatal(http.ListenAndServe(":3334", r))
} }

@ -0,0 +1,11 @@
{{- define "title" }}404 Not Found - {{ template "sitetitle" . }}{{- end -}}
{{- define "results" -}}
<div class="center">
<br>
<h1>404 Not Found</h1>
<p>Looks like this page doesn't exist?</p>
</div>
{{- end -}}
{{- template "index" . -}}