diff --git a/dict/main.go b/dict/main.go index 523a5be..d63fb4c 100644 --- a/dict/main.go +++ b/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)) } diff --git a/dict/templates/404.html b/dict/templates/404.html new file mode 100644 index 0000000..3830f68 --- /dev/null +++ b/dict/templates/404.html @@ -0,0 +1,11 @@ +{{- define "title" }}404 Not Found - {{ template "sitetitle" . }}{{- end -}} + +{{- define "results" -}} +
+
+

404 Not Found

+

Looks like this page doesn't exist?

+
+{{- end -}} + +{{- template "index" . -}} \ No newline at end of file