From 1387a2938e66fe3d1802de046f0eb2a92988b6a5 Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Fri, 29 Apr 2022 09:39:39 +0000 Subject: [PATCH] not found --- backend/server/server.go | 8 ++++++-- backend/templates/notFound.html | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 backend/templates/notFound.html diff --git a/backend/server/server.go b/backend/server/server.go index b9cfb1f..0121753 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -83,7 +83,7 @@ func StartServer(world *model.DfWorld, static embed.FS) { srv.router.PathPrefix("/load").Handler(srv.loader) - spa := spaHandler{staticFS: static, staticPath: "static", indexPath: "index.html"} + spa := spaHandler{server: srv, staticFS: static, staticPath: "static", indexPath: "index.html"} srv.router.PathPrefix("/").Handler(spa) OpenBrowser("http://localhost:8080") @@ -93,6 +93,7 @@ func StartServer(world *model.DfWorld, static embed.FS) { } type spaHandler struct { + server *DfServer staticFS embed.FS staticPath string indexPath string @@ -115,7 +116,10 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Println(path) index, err := h.staticFS.ReadFile(h.staticPath + "/" + h.indexPath) if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + err = h.server.templates.Render(w, "notFound.html", nil) + if err != nil { + httpError(w, err) + } return } w.Header().Set("Content-Type", "text/html; charset=utf-8") diff --git a/backend/templates/notFound.html b/backend/templates/notFound.html new file mode 100644 index 0000000..0506d3b --- /dev/null +++ b/backend/templates/notFound.html @@ -0,0 +1,9 @@ +{{template "layout.html" .}} + +{{define "title"}}Not Found{{end}} + +{{define "content"}} + +Not found + +{{- end }} \ No newline at end of file