mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
feat(dashboard): add sigle-page-app html5 pushstate support
This commit is contained in:
parent
d4b33c7e12
commit
77270c6b00
@ -35,6 +35,10 @@ func memoryFileServer(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
func getDashDir() string {
|
||||
return os.Getenv("ETCD_DASHBOARD_DIR")
|
||||
}
|
||||
|
||||
// DashboardHttpHandler either uses the compiled in virtual filesystem for the
|
||||
// dashboard assets or if ETCD_DASHBOARD_DIR is set uses that as the source of
|
||||
// assets.
|
||||
@ -42,7 +46,7 @@ func HttpHandler() (handler http.Handler) {
|
||||
handler = http.HandlerFunc(memoryFileServer)
|
||||
|
||||
// Serve the dashboard from a filesystem if the magic env variable is enabled
|
||||
dashDir := os.Getenv("ETCD_DASHBOARD_DIR")
|
||||
dashDir := getDashDir()
|
||||
if len(dashDir) != 0 {
|
||||
log.Debugf("Using dashboard directory %s", dashDir)
|
||||
handler = http.FileServer(http.Dir(dashDir))
|
||||
@ -50,3 +54,10 @@ func HttpHandler() (handler http.Handler) {
|
||||
|
||||
return handler
|
||||
}
|
||||
|
||||
// Always returns the index.html page.
|
||||
func IndexPage(w http.ResponseWriter, req *http.Request) {
|
||||
dashDir := getDashDir()
|
||||
http.ServeFile(w, req, path.Join(dashDir, "index.html"))
|
||||
return
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ func addSlash(w http.ResponseWriter, req *http.Request) {
|
||||
func HttpHandler(addr string) http.Handler {
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/dashboard", addSlash)
|
||||
r.PathPrefix("/dashboard/").Handler(http.StripPrefix("/dashboard/", dashboard.HttpHandler()))
|
||||
|
||||
r.PathPrefix("/dashboard/static/").Handler(http.StripPrefix("/dashboard/static/", dashboard.HttpHandler()))
|
||||
r.HandleFunc("/dashboard{path:.*}", dashboard.IndexPage)
|
||||
|
||||
r.PathPrefix("/v2/lock").Handler(http.StripPrefix("/v2/lock", lock2.NewHandler(addr)))
|
||||
r.PathPrefix("/v2/leader").Handler(http.StripPrefix("/v2/leader", leader2.NewHandler(addr)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user