From ff39f90abd8c19a4d22aef54c3384b447ad276b8 Mon Sep 17 00:00:00 2001 From: Vasiliy Faronov Date: Fri, 12 Mar 2021 15:47:00 +0300 Subject: [PATCH] fix serving static files with -base I deleted the commented-out block because it hasn't been touched in half a year now. --- src/server/handlers.go | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/server/handlers.go b/src/server/handlers.go index 3f54d5b..1d6c6ad 100644 --- a/src/server/handlers.go +++ b/src/server/handlers.go @@ -14,9 +14,6 @@ import ( "strings" ) -// TODO: gzip? -var StaticHandler = http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP - var routes []Route = []Route{ p("/", IndexHandler).ManualAuth(), p("/static/*path", StaticHandler).ManualAuth(), @@ -78,33 +75,10 @@ func IndexHandler(rw http.ResponseWriter, req *http.Request) { assets.Render("index.html", rw, nil) } -/* func StaticHandler(rw http.ResponseWriter, req *http.Request) { - http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP(rw, req) - ctype := mime.TypeByExtension(filepath.Ext(path)) - - if assets != nil { - if asset, ok := assets[path]; ok { - if req.Header.Get("if-none-match") == asset.etag { - rw.WriteHeader(http.StatusNotModified) - return - } - rw.Header().Set("Content-Type", ctype) - rw.Header().Set("Content-Encoding", "gzip") - rw.Header().Set("Etag", asset.etag) - rw.Write(*asset.gzip()) - } - } - - f, err := os.Open("assets/" + path) - if err != nil { - return - } - defer f.Close() - rw.Header().Set("Content-Type", ctype) - io.Copy(rw, f) + // TODO: gzip? + http.StripPrefix(BasePath+"/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP(rw, req) } -*/ func StatusHandler(rw http.ResponseWriter, req *http.Request) { writeJSON(rw, map[string]interface{}{