admin: fix static routing

This commit is contained in:
nemunaire 2016-01-22 17:34:34 +01:00
parent db2e286677
commit c9e4d3e27c
2 changed files with 23 additions and 5 deletions

View File

@ -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))

View File

@ -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"))
}