From 5620f88635d815a20a8cfbfb07f7c5a61d8fadb6 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Wed, 16 Oct 2013 18:59:25 -0700 Subject: [PATCH] feat(server): insert the mod path --- mod/dashboard/dashboard.go | 3 +++ mod/mod.go | 11 +++++++---- server/server.go | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/mod/dashboard/dashboard.go b/mod/dashboard/dashboard.go index 7941fc7a3..0a74252a0 100644 --- a/mod/dashboard/dashboard.go +++ b/mod/dashboard/dashboard.go @@ -7,10 +7,12 @@ import ( "path" "time" + "github.com/coreos/etcd/log" "github.com/coreos/etcd/mod/dashboard/resources" ) func memoryFileServer(w http.ResponseWriter, req *http.Request) { + log.Debugf("[recv] %s %s [%s]", req.Method, req.URL.Path, req.RemoteAddr) upath := req.URL.Path if len(upath) == 0 { upath = "index.html" @@ -42,6 +44,7 @@ func HttpHandler() (handler http.Handler) { // Serve the dashboard from a filesystem if the magic env variable is enabled dashDir := os.Getenv("ETCD_DASHBOARD_DIR") if len(dashDir) != 0 { + log.Debugf("Using dashboard directory %s", dashDir) handler = http.FileServer(http.Dir(dashDir)) } diff --git a/mod/mod.go b/mod/mod.go index f764d6c2f..741b19002 100644 --- a/mod/mod.go +++ b/mod/mod.go @@ -3,13 +3,16 @@ package mod import ( "net/http" + "github.com/coreos/etcd/mod/dashboard" + "github.com/gorilla/mux" ) var ServeMux *http.Handler -func init() { - // TODO: Use a Gorilla mux to handle this in 0.2 and remove the strip - handler := http.StripPrefix("/etcd/mod/dashboard/", dashboard.HttpHandler()) - ServeMux = &handler +func HttpHandler() (handler http.Handler) { + modMux := mux.NewRouter() + modMux.PathPrefix("/dashboard/"). + Handler(http.StripPrefix("/dashboard/", dashboard.HttpHandler())) + return modMux } diff --git a/server/server.go b/server/server.go index 48757ad2b..f7d37a73b 100644 --- a/server/server.go +++ b/server/server.go @@ -12,6 +12,7 @@ import ( etcdErr "github.com/coreos/etcd/error" "github.com/coreos/etcd/log" + "github.com/coreos/etcd/mod" "github.com/coreos/etcd/server/v1" "github.com/coreos/etcd/server/v2" "github.com/coreos/etcd/store" @@ -55,6 +56,7 @@ func New(name string, urlStr string, listenHost string, tlsConf *TLSConfig, tlsI s.handleFunc("/version", s.GetVersionHandler).Methods("GET") s.installV1() s.installV2() + s.installMod() return s } @@ -119,6 +121,11 @@ func (s *Server) installV2() { s.handleFunc("/v2/speedTest", s.SpeedTestHandler).Methods("GET") } +func (s *Server) installMod() { + r := s.Handler.(*mux.Router) + r.PathPrefix("/etcd/mod").Handler(http.StripPrefix("/etcd/mod", mod.HttpHandler())) +} + // Adds a v1 server handler to the router. func (s *Server) handleFuncV1(path string, f func(http.ResponseWriter, *http.Request, v1.Server) error) *mux.Route { return s.handleFunc(path, func(w http.ResponseWriter, req *http.Request) error {