From dbdda5ed3d58e2d97fd0de0c765ecafc3ac7b339 Mon Sep 17 00:00:00 2001 From: phartenfeller Date: Mon, 28 Sep 2020 11:59:03 +0200 Subject: [PATCH] custom header documentation --- docs/header-config.md | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/header-config.md diff --git a/docs/header-config.md b/docs/header-config.md new file mode 100644 index 0000000..79840c9 --- /dev/null +++ b/docs/header-config.md @@ -0,0 +1,74 @@ +# Header Config + +With the header config, you can specify custom [HTTP Header](https://developer.mozilla.org/de/docs/Web/HTTP/Headers) for the responses of certain file types and paths. + +## Config + +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. + +Example command to add to the docker run command: + +``` +-v /your/path/to/the/config/myConfig.json:/config/headerConfig.json +``` + +On startup, the container will log the found header rules. + +## Example headerConfig.json + +```json +{ + "configs": [ + { + "path": "*", + "fileExtension": "html", + "headers": [ + { + "key": "cache-control", + "value": "public, max-age=0, must-revalidate" + }, + { + "key": "Strict-Transport-Security", + "value": "max-age=31536000; includeSubDomains;" + } + ] + }, + { + "path": "*", + "fileExtension": "css", + "headers": [ + { + "key": "cache-control", + "value": "public, max-age=31536000, immutable" + } + ] + }, + { + "path": "/page-data", + "fileExtension": "json", + "headers": [ + { + "key": "cache-control", + "value": "public, max-age=0, must-revalidate" + }, + { + "key": "content-language", + "value": "en" + } + ] + }, + { + "path": "/static/", + "fileExtension": "*", + "headers": [ + { + "key": "cache-control", + "value": "public, max-age=31536000, immutable" + } + ] + } + ] +} +```