diff --git a/config/config.go b/config/config.go index ad99bc884..2bee33796 100644 --- a/config/config.go +++ b/config/config.go @@ -108,11 +108,13 @@ type Registry struct { } type Static struct { - Routes string + NoRouteHTMLPath string + Routes string } type File struct { - Path string + NoRouteHTMLPath string + Path string } type Consul struct { diff --git a/config/load.go b/config/load.go index 692379fd7..282f4fd7c 100644 --- a/config/load.go +++ b/config/load.go @@ -156,7 +156,9 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c f.DurationVar(&cfg.Registry.Timeout, "registry.timeout", defaultConfig.Registry.Timeout, "timeout for registry to become available") f.DurationVar(&cfg.Registry.Retry, "registry.retry", defaultConfig.Registry.Retry, "retry interval during startup") f.StringVar(&cfg.Registry.File.Path, "registry.file.path", defaultConfig.Registry.File.Path, "path to file based routing table") + f.StringVar(&cfg.Registry.File.NoRouteHTMLPath, "registry.file.noroutehtmlpath", defaultConfig.Registry.File.NoRouteHTMLPath, "path to file for HTML returned when no route is found") f.StringVar(&cfg.Registry.Static.Routes, "registry.static.routes", defaultConfig.Registry.Static.Routes, "static routes") + f.StringVar(&cfg.Registry.Static.NoRouteHTMLPath, "registry.static.noroutehtmlpath", defaultConfig.Registry.Static.NoRouteHTMLPath, "path to file for HTML returned when no route is found") f.StringVar(&cfg.Registry.Consul.Addr, "registry.consul.addr", defaultConfig.Registry.Consul.Addr, "address of the consul agent") f.StringVar(&cfg.Registry.Consul.Token, "registry.consul.token", defaultConfig.Registry.Consul.Token, "token for consul agent") f.StringVar(&cfg.Registry.Consul.KVPath, "registry.consul.kvpath", defaultConfig.Registry.Consul.KVPath, "consul KV path for manual overrides") diff --git a/fabio.properties b/fabio.properties index 809295115..578d764ad 100644 --- a/fabio.properties +++ b/fabio.properties @@ -535,6 +535,14 @@ # registry.static.routes = +# registry.static.noroutehtmlpath configures the KV path for the HTML of the +# noroutes page. +# +# The default is +# +# registry.static.noroutehtmlpath = + + # registry.file.path configures a file based routing table. # The value configures the path to the file with the routing table. # @@ -543,6 +551,14 @@ # registry.file.path = +# registry.file.noroutehtmlpath configures the KV path for the HTML of the +# noroutes page. +# +# The default is +# +# registry.file.noroutehtmlpath = + + # registry.consul.addr configures the address of the consul agent to connect to. # # The default is @@ -574,7 +590,7 @@ # # The default is # -# registry.consul.kvpath = /fabio/noroutes.html +# registry.consul.noroutehtmlpath = /fabio/noroutes.html # registry.consul.service.status configures the valid service status # values for services included in the routing table. diff --git a/main.go b/main.go index f1ccda211..53f60a75d 100644 --- a/main.go +++ b/main.go @@ -343,9 +343,9 @@ func initBackend(cfg *config.Config) { for { switch cfg.Registry.Backend { case "file": - registry.Default, err = file.NewBackend(cfg.Registry.File.Path) + registry.Default, err = file.NewBackend(&cfg.Registry.File) case "static": - registry.Default, err = static.NewBackend(cfg.Registry.Static.Routes) + registry.Default, err = static.NewBackend(&cfg.Registry.Static) case "consul": registry.Default, err = consul.NewBackend(&cfg.Registry.Consul) default: diff --git a/registry/file/backend.go b/registry/file/backend.go index ff1109d5d..d9bdc1fd2 100644 --- a/registry/file/backend.go +++ b/registry/file/backend.go @@ -6,15 +6,17 @@ import ( "io/ioutil" "log" + "github.com/fabiolb/fabio/config" "github.com/fabiolb/fabio/registry" "github.com/fabiolb/fabio/registry/static" ) -func NewBackend(filename string) (registry.Backend, error) { - data, err := ioutil.ReadFile(filename) +func NewBackend(cfg *config.File) (registry.Backend, error) { + data, err := ioutil.ReadFile(cfg.Path) if err != nil { - log.Println("[ERROR] Cannot read routes from ", filename) + log.Println("[ERROR] Cannot read routes from ", cfg.Path) return nil, err } - return static.NewBackend(string(data)) + staticCfg := config.Static{cfg.NoRouteHTMLPath, string(data)} + return static.NewBackend(&staticCfg) } diff --git a/registry/static/backend.go b/registry/static/backend.go index a2fc86080..064d06569 100644 --- a/registry/static/backend.go +++ b/registry/static/backend.go @@ -6,17 +6,17 @@ import ( "io/ioutil" "log" + "github.com/fabiolb/fabio/config" "github.com/fabiolb/fabio/registry" "github.com/fabiolb/fabio/route" ) -type be struct{} - -var staticRoutes string +type be struct { + cfg *config.Static +} -func NewBackend(routes string) (registry.Backend, error) { - staticRoutes = routes - return &be{}, nil +func NewBackend(cfg *config.Static) (registry.Backend, error) { + return &be{cfg}, nil } func (b *be) Register() error { @@ -37,7 +37,7 @@ func (b *be) WriteManual(value string, version uint64) (ok bool, err error) { func (b *be) WatchServices() chan string { ch := make(chan string, 1) - ch <- staticRoutes + ch <- b.cfg.Routes return ch } @@ -48,9 +48,9 @@ func (b *be) WatchManual() chan string { // WatchNoRouteHTML implementation that reads the noroute html from a // noroute.html file if it exists func (b *be) WatchNoRouteHTML() chan string { - data, err := ioutil.ReadFile("noroute.html") + data, err := ioutil.ReadFile(b.cfg.NoRouteHTMLPath) if err != nil { - log.Println("[WARN] No noroute.html to read noroute html from") + log.Printf("[WARN] Could not read NoRouteHTMLPath (%s)", b.cfg.NoRouteHTMLPath) } route.SetHTML(string(data)) return make(chan string)