diff --git a/etcd_handlers.go b/etcd_handlers.go index 0843aa48a..fdb40f650 100644 --- a/etcd_handlers.go +++ b/etcd_handlers.go @@ -19,6 +19,7 @@ package main import ( "fmt" "net/http" + "os" "strconv" "strings" @@ -41,6 +42,7 @@ func NewEtcdMuxer() *http.ServeMux { etcdMux.Handle("/"+version+"/stats/", errorHandler(StatsHttpHandler)) etcdMux.Handle("/version", errorHandler(VersionHttpHandler)) etcdMux.HandleFunc("/test/", TestHttpHandler) + etcdMux.Handle("/dashboard/", DashboardHttpHandler()) return etcdMux } @@ -276,6 +278,19 @@ func GetHttpHandler(w http.ResponseWriter, req *http.Request) error { } +// 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. +func DashboardHttpHandler() http.Handler { + dashDir := os.Getenv("ETCD_DASHBOARD_DIR") + + if len(dashDir) == 0 { + dashDir = "./" + } + + return http.StripPrefix("/dashboard/", http.FileServer(http.Dir(dashDir))) +} + // Watch handler func WatchHttpHandler(w http.ResponseWriter, req *http.Request) error { key := req.URL.Path[len("/v1/watch/"):]