Fix use of path given|

by -static when compiled in dev
This commit is contained in:
nemunaire 2019-10-16 15:36:50 +02:00
parent deb4ff03ca
commit 80dca4434d

View File

@ -12,8 +12,14 @@ import (
var StaticDir string = "static/" var StaticDir string = "static/"
func init() { func init() {
mux.Handle("/css/", http.FileServer(http.Dir(StaticDir))) mux.HandleFunc("/css/", func(w http.ResponseWriter, r *http.Request) {
mux.Handle("/js/", http.FileServer(http.Dir(StaticDir))) 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") 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 { func sanitizeStaticOptions() error {
StaticDir, _ := filepath.Abs("static") StaticDir, _ = filepath.Abs(StaticDir)
if _, err := os.Stat(StaticDir); os.IsNotExist(err) { if _, err := os.Stat(StaticDir); os.IsNotExist(err) {
StaticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static")) StaticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static"))
if _, err := os.Stat(StaticDir); os.IsNotExist(err) { if _, err := os.Stat(StaticDir); os.IsNotExist(err) {