From 80dca4434d1d4d504a8b4fd0e9c81e758e1c9135 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 16 Oct 2019 15:36:50 +0200 Subject: [PATCH] Fix use of path given| by -static when compiled in dev --- static-dev.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/static-dev.go b/static-dev.go index 36215fa..0dcb2dd 100644 --- a/static-dev.go +++ b/static-dev.go @@ -12,8 +12,14 @@ import ( var StaticDir string = "static/" func init() { - mux.Handle("/css/", http.FileServer(http.Dir(StaticDir))) - mux.Handle("/js/", http.FileServer(http.Dir(StaticDir))) + mux.HandleFunc("/css/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/css") + serveStaticAsset(w, r, r.URL.Path) + }) + mux.HandleFunc("/js/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/javascript") + serveStaticAsset(w, r, r.URL.Path) + }) flag.StringVar(&StaticDir, "static", StaticDir, "Directory containing static files") } @@ -28,7 +34,7 @@ func serveStaticAsset(w http.ResponseWriter, r *http.Request, url string) { } func sanitizeStaticOptions() error { - StaticDir, _ := filepath.Abs("static") + StaticDir, _ = filepath.Abs(StaticDir) if _, err := os.Stat(StaticDir); os.IsNotExist(err) { StaticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static")) if _, err := os.Stat(StaticDir); os.IsNotExist(err) {