Config path can be specified with a parameter

This commit is contained in:
phartenfeller 2020-09-28 19:47:48 +02:00
parent 64bc411fc7
commit 3438532c3f
4 changed files with 21 additions and 12 deletions

View file

@ -40,7 +40,7 @@ docker run -d -p 80:8043 -v path/to/website:/srv/http --name goStatic pierrezemb
``` ```
./goStatic --help ./goStatic --help
Usage of /goStatic: Usage of ./goStatic:
-append-header HeaderName:Value -append-header HeaderName:Value
HTTP response header, specified as HeaderName:Value that should be added to all responses. HTTP response header, specified as HeaderName:Value that should be added to all responses.
-context string -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 basic auth. By default, password are randomly generated. Use --set-basic-auth to set it.
-enable-health -enable-health
Enable health check endpoint. You can call /health to get a 200 response. Useful for Kubernetes, OpenFaas, etc. 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 -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 -password-length int
Size of the randomized password (default 16) Size of the randomized password (default 16)
-path string -path string
@ -61,10 +67,6 @@ Usage of /goStatic:
The listening port (default 8043) The listening port (default 8043)
-set-basic-auth string -set-basic-auth string
Define the basic auth. Form must be user:password 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 #### Fallback

View file

@ -50,11 +50,11 @@ func logHeaderConfig(config HeaderConfig) {
fmt.Println("------------------------------") fmt.Println("------------------------------")
} }
func initHeaderConfig() bool { func initHeaderConfig(headerConfigPath string) bool {
headerConfigValid := false headerConfigValid := false
if fileExists("/config/headerConfig.json") { if fileExists(headerConfigPath) {
jsonFile, err := os.Open("/config/headerConfig.json") jsonFile, err := os.Open(headerConfigPath)
if err != nil { if err != nil {
fmt.Println("Cant't read header config file. Error:") fmt.Println("Cant't read header config file. Error:")
fmt.Println(err) fmt.Println(err)

View file

@ -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. 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: 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. On startup, the container will log the found header rules.

View file

@ -30,6 +30,7 @@ var (
sizeRandom = flag.Int("password-length", 16, "Size of the randomized password") sizeRandom = flag.Int("password-length", 16, "Size of the randomized password")
logRequest = flag.Bool("enable-logging", false, "Enable log request") logRequest = flag.Bool("enable-logging", false, "Enable log request")
httpsPromote = flag.Bool("https-promote", false, "All HTTP requests should be redirected to HTTPS") 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 username string
password string password string
@ -123,7 +124,7 @@ func main() {
handler = authMiddleware(handler) handler = authMiddleware(handler)
} }
headerConfigValid := initHeaderConfig() headerConfigValid := initHeaderConfig(*headerConfigPath)
if headerConfigValid { if headerConfigValid {
handler = customHeadersMiddleware(handler) handler = customHeadersMiddleware(handler)
} }