Browse Source

feat(etcd_handlers): add the dashboard URL

/dashboard serves a dashboard now
Brandon Philips 12 years ago
parent
commit
5a4f096647
1 changed files with 15 additions and 0 deletions
  1. 15 0
      etcd_handlers.go

+ 15 - 0
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/"):]