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