From 002595a4071453b1b15eb38f0514358bb6483138 Mon Sep 17 00:00:00 2001 From: breel Date: Fri, 28 Aug 2020 16:16:35 -0600 Subject: [PATCH] Serve /index.html on 404 --- server/static.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/static.go b/server/static.go index 21b0a57..0c429a7 100644 --- a/server/static.go +++ b/server/static.go @@ -4,9 +4,14 @@ import ( "local/dndex/config" "local/simpleserve/simpleserve" "net/http" + "os" + "path" ) func (rest *REST) static(w http.ResponseWriter, r *http.Request) { + if _, err := os.Stat(path.Join(config.New().StaticRoot, r.URL.Path)); os.IsNotExist(err) { + r.URL.Path = "/" + } simpleserve.SetContentTypeIfMedia(w, r) server := http.FileServer(http.Dir(config.New().StaticRoot)) server.ServeHTTP(w, r)