diff --git a/README.md b/README.md index 72a8add..36d842b 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ docker run -d -p 80:8043 -v path/to/website:/srv/http --name goStatic pierrezemb ``` ./goStatic --help -Usage of /goStatic: +Usage of ./goStatic: -append-header HeaderName:Value HTTP response header, specified as HeaderName:Value that should be added to all responses. -context string @@ -51,8 +51,14 @@ Usage of /goStatic: Enable basic auth. By default, password are randomly generated. Use --set-basic-auth to set it. -enable-health Enable health check endpoint. You can call /health to get a 200 response. Useful for Kubernetes, OpenFaas, etc. + -enable-logging + Enable log request -fallback string - Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html). + Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html) + -header-config-path string + Path to the config file for custom response headers (default "/config/headerConfig.json") + -https-promote + All HTTP requests should be redirected to HTTPS -password-length int Size of the randomized password (default 16) -path string @@ -61,10 +67,6 @@ Usage of /goStatic: The listening port (default 8043) -set-basic-auth string Define the basic auth. Form must be user:password - -https-promote - Connections to http: are redirected to https: - -enable-logging - Writes a simple log entry for requests to the server ``` #### Fallback diff --git a/customHeaders.go b/customHeaders.go index 6d17d16..1e819bf 100644 --- a/customHeaders.go +++ b/customHeaders.go @@ -50,11 +50,11 @@ func logHeaderConfig(config HeaderConfig) { fmt.Println("------------------------------") } -func initHeaderConfig() bool { +func initHeaderConfig(headerConfigPath string) bool { headerConfigValid := false - if fileExists("/config/headerConfig.json") { - jsonFile, err := os.Open("/config/headerConfig.json") + if fileExists(headerConfigPath) { + jsonFile, err := os.Open(headerConfigPath) if err != nil { fmt.Println("Cant't read header config file. Error:") fmt.Println(err) diff --git a/docs/header-config.md b/docs/header-config.md index 79840c9..b97255d 100644 --- a/docs/header-config.md +++ b/docs/header-config.md @@ -6,12 +6,18 @@ With the header config, you can specify custom [HTTP Header](https://developer.m You have to create a JSON file that serves as a config. The JSON must contain a `configs` array. For every entry, you can specify a certain path that must be matched as well as a file extension. You can use the `*` symbol to use the config entry for any path or filename. Note that the path option only matches the requested path from the start. Thatswhy you have to start with a `/` and can use paths like `/files/static/css`. The `headers` array includes a key-value pair of the actual header rule. The headers are not parsed so double check your spelling and test your site. -The created JSON config has to be mounted into the container via a volume into `/config/headerConfig.json`. When this file does not exist inside the container, the header middleware will not be active. +The created JSON config has to be mounted into the container via a volume into `/config/headerConfig.json` per default. When this file does not exist inside the container, the header middleware will not be active. Example command to add to the docker run command: ``` --v /your/path/to/the/config/myConfig.json:/config/headerConfig.json +docker run ... -v /your/path/to/the/config/myConfig.json:/config/headerConfig.json +``` + +You can also specify where you want to mount your config into with the `header-config-path` flag: + +``` +docker run ... -v /your/path/to/the/config/myConfig.json:/other/path/myConfig.json -header-config-path=/other/path/myConfig.json ``` On startup, the container will log the found header rules. diff --git a/main.go b/main.go index b2617e6..2590263 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ var ( sizeRandom = flag.Int("password-length", 16, "Size of the randomized password") logRequest = flag.Bool("enable-logging", false, "Enable log request") httpsPromote = flag.Bool("https-promote", false, "All HTTP requests should be redirected to HTTPS") + headerConfigPath = flag.String("header-config-path", "/config/headerConfig.json", "Path to the config file for custom response headers") username string password string @@ -123,7 +124,7 @@ func main() { handler = authMiddleware(handler) } - headerConfigValid := initHeaderConfig() + headerConfigValid := initHeaderConfig(*headerConfigPath) if headerConfigValid { handler = customHeadersMiddleware(handler) }