diff --git a/admin/main.go b/admin/main.go index 8920323f..f126541f 100644 --- a/admin/main.go +++ b/admin/main.go @@ -31,8 +31,13 @@ func main() { flag.StringVar(&CloudPassword, "cloudpass", "", "Password used to sync") flag.Parse() + var staticDir string var err error log.Println("Checking paths...") + if staticDir, err = filepath.Abs("./static/"); err != nil { + log.Fatal(err) + os.Exit(1) + } if fic.FilesDir, err = filepath.Abs(fic.FilesDir); err != nil { log.Fatal(err) os.Exit(1) @@ -45,6 +50,10 @@ func main() { log.Fatal(err) os.Exit(1) } + if fic.FilesDir, err = filepath.Abs(fic.FilesDir); err != nil { + log.Fatal(err) + os.Exit(1) + } log.Println("Opening database...") if err := fic.DBInit(*dbfile); err != nil { @@ -66,9 +75,9 @@ func main() { log.Println("Registering handlers...") mux := http.NewServeMux() mux.Handle("/api/", http.StripPrefix("/api", ApiHandler())) - mux.HandleFunc("/teams", StaticRouting) - mux.HandleFunc("/themes", StaticRouting) - mux.Handle("/", http.FileServer(http.Dir("./static/"))) + mux.Handle("/teams/", StaticHandler(staticDir)) + mux.Handle("/themes/", StaticHandler(staticDir)) + mux.Handle("/", http.FileServer(http.Dir(staticDir))) http.HandleFunc("/", mux.ServeHTTP) log.Println(fmt.Sprintf("Ready, listening on %s", *bind)) diff --git a/admin/static.go b/admin/static.go index f82ab08b..c0eb7ae3 100644 --- a/admin/static.go +++ b/admin/static.go @@ -2,8 +2,17 @@ package main import ( "net/http" + "path" ) -func StaticRouting(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "./static/index.html") +type staticRouting struct{ + StaticDir string +} + +func StaticHandler(staticDir string) http.Handler { + return staticRouting{staticDir} +} + +func (a staticRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, path.Join(a.StaticDir, "index.html")) }