mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 02:48:19 +00:00
agent: inline uiDir field
uiDir can be inlined as agent.config.UIDir
This commit is contained in:
parent
8f381d62f6
commit
327401e7ee
@ -27,7 +27,6 @@ type HTTPServer struct {
|
|||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
uiDir string
|
|
||||||
addr string
|
addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +79,6 @@ func NewHTTPServers(agent *Agent) ([]*HTTPServer, error) {
|
|||||||
mux: mux,
|
mux: mux,
|
||||||
listener: list,
|
listener: list,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: log.New(logOutput, "", log.LstdFlags),
|
||||||
uiDir: config.UIDir,
|
|
||||||
addr: httpAddr.String(),
|
addr: httpAddr.String(),
|
||||||
}
|
}
|
||||||
srv.registerHandlers(config.EnableDebug)
|
srv.registerHandlers(config.EnableDebug)
|
||||||
@ -132,7 +130,6 @@ func NewHTTPServers(agent *Agent) ([]*HTTPServer, error) {
|
|||||||
mux: mux,
|
mux: mux,
|
||||||
listener: list,
|
listener: list,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: log.New(logOutput, "", log.LstdFlags),
|
||||||
uiDir: config.UIDir,
|
|
||||||
addr: httpAddr.String(),
|
addr: httpAddr.String(),
|
||||||
}
|
}
|
||||||
srv.registerHandlers(config.EnableDebug)
|
srv.registerHandlers(config.EnableDebug)
|
||||||
@ -293,8 +290,8 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use the custom UI dir if provided.
|
// Use the custom UI dir if provided.
|
||||||
if s.uiDir != "" {
|
if s.agent.config.UIDir != "" {
|
||||||
s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.Dir(s.uiDir))))
|
s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.Dir(s.agent.config.UIDir))))
|
||||||
} else if s.agent.config.EnableUI {
|
} else if s.agent.config.EnableUI {
|
||||||
s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(assetFS())))
|
s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(assetFS())))
|
||||||
}
|
}
|
||||||
@ -391,7 +388,7 @@ func (s *HTTPServer) marshalJSON(req *http.Request, obj interface{}) ([]byte, er
|
|||||||
|
|
||||||
// Returns true if the UI is enabled.
|
// Returns true if the UI is enabled.
|
||||||
func (s *HTTPServer) IsUIEnabled() bool {
|
func (s *HTTPServer) IsUIEnabled() bool {
|
||||||
return s.uiDir != "" || s.agent.config.EnableUI
|
return s.agent.config.UIDir != "" || s.agent.config.EnableUI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renders a simple index page
|
// Renders a simple index page
|
||||||
|
@ -33,7 +33,7 @@ func TestUiIndex(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Create file
|
// Create file
|
||||||
path := filepath.Join(srv.uiDir, "my-file")
|
path := filepath.Join(srv.agent.config.UIDir, "my-file")
|
||||||
if err := ioutil.WriteFile(path, []byte("test"), 777); err != nil {
|
if err := ioutil.WriteFile(path, []byte("test"), 777); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user