Skip to content

Commit

Permalink
Add configurable web ui static files path.
Browse files Browse the repository at this point in the history
  • Loading branch information
Buhrietoe committed Sep 15, 2016
1 parent df92cb7 commit 70e9507
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
brood
brood.yml
brood.json
brood.toml
brood.tar.xz
static/dist/
static/.tmp/
static/node_modules/
release/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ Use the following environment variables to configure brood:

BROOD_ADDRESS=127.0.0.1 # DEFAULT: 0.0.0.0
BROOD_PORT=1234 # DEFAULT: 3456
BROOD_UI=static # DEFAULT: static/dist; This is the path to the web assets

Configuration can also be done in a json/yaml/toml file. If there is a problem reading the file, brood will continue with its defaults.

**YAML**

address: 127.0.0.1
port: 1234
ui: /usr/local/src/brood/static

**JSON**

{
"address": "127.0.0.1",
"port": "1234"
"port": "1234",
"ui": "/usr/local/src/brood/static"
}

**TOML**

address = 127.0.0.1
port = 1234
ui = /usr/local/src/brood/static

Development
-----
Expand Down
8 changes: 7 additions & 1 deletion app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var (
Address = "" // Address to bind on
Port = "" // Port for web interface to listen on
UI = "" // Path to the static files web folder
ListenString = "" // Complete string of address:port to listen on
)

Expand All @@ -20,11 +21,13 @@ func LoadConfig(configFile string) error {
// Set defaults
viper.SetDefault("address", "0.0.0.0")
viper.SetDefault("port", "3456")
viper.SetDefault("ui", "static/dist")

filename := filepath.Base(configFile)
viper.SetConfigName(filename[:len(filename)-len(filepath.Ext(filename))])
viper.AddConfigPath(filepath.Dir(configFile))
viper.SetConfigType("yaml")
viper.SetConfigType("json")

err := viper.ReadInConfig()
if err != nil {
log.Printf("unable to read config file %v: %v\n", configFile, err)
Expand All @@ -37,6 +40,9 @@ func LoadConfig(configFile string) error {
viper.BindEnv("port")
Port = viper.GetString("port")

viper.BindEnv("ui")
UI = viper.GetString("ui")

ListenString = Address + ":" + Port

return nil
Expand Down
3 changes: 2 additions & 1 deletion app/route.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"github.com/Buhrietoe/brood/app/config"
"github.com/labstack/echo"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func BuildApp() (e *echo.Echo) {
// }
// alertsController.Init()

e.Static("/static", "static/dist")
e.Static("/static", config.UI)
e.GET("/", func(ctx echo.Context) error {
return ctx.Redirect(301, "/static/index.html")
})
Expand Down

0 comments on commit 70e9507

Please sign in to comment.