feat(server): insert the mod path

This commit is contained in:
Brandon Philips 2013-10-16 18:59:25 -07:00
parent 56bbab74ca
commit 5620f88635
3 changed files with 17 additions and 4 deletions

View File

@ -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))
}

View File

@ -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
}

View File

@ -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 {