generated from ElnuDev/go-project
Add 404 page
This commit is contained in:
parent
33ecd1a539
commit
dee29d1277
2 changed files with 26 additions and 1 deletions
16
dict/main.go
16
dict/main.go
|
@ -431,6 +431,20 @@ func main() {
|
|||
},
|
||||
[]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))
|
||||
}
|
||||
|
|
11
dict/templates/404.html
Normal file
11
dict/templates/404.html
Normal file
|
@ -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" . -}}
|
Reference in a new issue