Browse Source

feat(server): insert the mod path

Brandon Philips 12 years ago
parent
commit
5620f88635
3 changed files with 17 additions and 4 deletions
  1. 3 0
      mod/dashboard/dashboard.go
  2. 7 4
      mod/mod.go
  3. 7 0
      server/server.go

+ 3 - 0
mod/dashboard/dashboard.go

@@ -7,10 +7,12 @@ import (
 	"path"
 	"path"
 	"time"
 	"time"
 
 
+	"github.com/coreos/etcd/log"
 	"github.com/coreos/etcd/mod/dashboard/resources"
 	"github.com/coreos/etcd/mod/dashboard/resources"
 )
 )
 
 
 func memoryFileServer(w http.ResponseWriter, req *http.Request) {
 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
 	upath := req.URL.Path
 	if len(upath) == 0 {
 	if len(upath) == 0 {
 		upath = "index.html"
 		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
 	// Serve the dashboard from a filesystem if the magic env variable is enabled
 	dashDir := os.Getenv("ETCD_DASHBOARD_DIR")
 	dashDir := os.Getenv("ETCD_DASHBOARD_DIR")
 	if len(dashDir) != 0 {
 	if len(dashDir) != 0 {
+		log.Debugf("Using dashboard directory %s", dashDir)
 		handler = http.FileServer(http.Dir(dashDir))
 		handler = http.FileServer(http.Dir(dashDir))
 	}
 	}
 
 

+ 7 - 4
mod/mod.go

@@ -3,13 +3,16 @@ package mod
 
 
 import (
 import (
 	"net/http"
 	"net/http"
+
 	"github.com/coreos/etcd/mod/dashboard"
 	"github.com/coreos/etcd/mod/dashboard"
+	"github.com/gorilla/mux"
 )
 )
 
 
 var ServeMux *http.Handler
 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
 }
 }

+ 7 - 0
server/server.go

@@ -12,6 +12,7 @@ import (
 
 
 	etcdErr "github.com/coreos/etcd/error"
 	etcdErr "github.com/coreos/etcd/error"
 	"github.com/coreos/etcd/log"
 	"github.com/coreos/etcd/log"
+	"github.com/coreos/etcd/mod"
 	"github.com/coreos/etcd/server/v1"
 	"github.com/coreos/etcd/server/v1"
 	"github.com/coreos/etcd/server/v2"
 	"github.com/coreos/etcd/server/v2"
 	"github.com/coreos/etcd/store"
 	"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.handleFunc("/version", s.GetVersionHandler).Methods("GET")
 	s.installV1()
 	s.installV1()
 	s.installV2()
 	s.installV2()
+	s.installMod()
 
 
 	return s
 	return s
 }
 }
@@ -119,6 +121,11 @@ func (s *Server) installV2() {
 	s.handleFunc("/v2/speedTest", s.SpeedTestHandler).Methods("GET")
 	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.
 // 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 {
 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 {
 	return s.handleFunc(path, func(w http.ResponseWriter, req *http.Request) error {