admin: fix static routing
This commit is contained in:
parent
db2e286677
commit
c9e4d3e27c
|
@ -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))
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user