Use relative path for static directory

This commit is contained in:
nemunaire 2017-10-11 18:42:51 +02:00
commit 9b27a67a21

View file

@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
)
var PublishedImgDir string
@ -43,10 +44,12 @@ 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"))
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/index.html") })
mux.Handle("/css/", http.FileServer(http.Dir("./static")))
mux.Handle("/js/", http.FileServer(http.Dir("./static")))
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filepath.Join(staticDir, "index.html")) })
mux.Handle("/css/", http.FileServer(http.Dir(staticDir)))
mux.Handle("/js/", http.FileServer(http.Dir(staticDir)))
mux.Handle("/api/", http.StripPrefix("/api", ApiHandler(authFunc)))