Better location for static path

This commit is contained in:
nemunaire 2018-02-16 11:41:03 +01:00
parent 7d82fbf5e7
commit 08fb2ad37c
1 changed files with 7 additions and 1 deletions

View File

@ -50,7 +50,13 @@ func main() {
log.Println("Registering handlers...")
authFunc := func (r *http.Request) (*User){ return Authenticate(*htpasswd, r) }
staticDir, _ := filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static"))
staticDir, _ := filepath.Abs("static")
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) {
log.Fatal(err)
}
}
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filepath.Join(staticDir, "index.html")) })