forked from static-web-server/static-web-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: config file and custom http headers [skip ci]
- Loading branch information
Showing
12 changed files
with
185 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# TOML Configuration File | ||
|
||
**`SWS`** can be configured using a [TOML](https://toml.io/en/) file in order to adjust the general server features as well as other advanced ones. | ||
|
||
It's disabled by default and can be enabled by passing an *string file path* via the `-w, --config-file` option or its equivalent [SERVER_CONFIG_FILE](./../configuration/environment-variables.md#server_config_file) env. | ||
|
||
## TOML File (Manifest) | ||
|
||
Below just an example showing all features with its default values. | ||
|
||
```toml | ||
[general] | ||
|
||
#### Address & Root dir | ||
host = "::" | ||
port = 8087 | ||
root = "docker/public" | ||
|
||
#### Logging | ||
log-level = "trace" | ||
|
||
#### Cache Control headers | ||
cache-control-headers = true | ||
|
||
#### Auto Compression | ||
compression = true | ||
|
||
#### Error pages | ||
page404 = "docker/public/404.html" | ||
page50x = "docker/public/50x.html" | ||
|
||
#### HTTP/2 + TLS | ||
http2 = false | ||
http2-tls-cert = "" | ||
http2-tls-key = "" | ||
|
||
#### Security headers | ||
security-headers = true | ||
|
||
#### CORS | ||
cors-allow-origins = "" | ||
cors-allow-headers = "" | ||
|
||
#### Directoy listing | ||
directory-listing = false | ||
directory-listing-order = 6 | ||
|
||
#### Basich Authentication | ||
basic-auth = "" | ||
|
||
#### File descriptor binding | ||
# fd = "" | ||
|
||
#### Worker threads | ||
threads-multiplier = 1 | ||
|
||
#### Grace period after a graceful shutdown | ||
grace-period = 0 | ||
|
||
#### Page fallback for 404s | ||
page-fallback = "" | ||
|
||
|
||
[advanced] | ||
|
||
#### .... | ||
``` | ||
|
||
### General options | ||
|
||
The TOML `[general]` section allows to adjust the current options actually available via the CLI/ENVs ones. | ||
|
||
So they are equivalent each other **except** the `-w, --config-file` option which is omitted and can not be used for obvious reasons. | ||
|
||
!!! info "Config file based features are optional" | ||
All server feature options via the configuration file are optional and can be omitted as needed. | ||
|
||
### Advanced options | ||
|
||
The TOML `[advanced]` section is intended for more complex features. | ||
|
||
### Precendence | ||
|
||
Whatever config file based feature option will take precedence over its CLI or ENV equivalent. | ||
|
||
## Usage | ||
|
||
The following command runs the server using an specific `config.toml` file. | ||
|
||
```sh | ||
static-web-server -w config.toml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Custom HTTP Headers | ||
|
||
**`SWS`** allows to customize the server [HTTP Response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers) on demand. | ||
|
||
## Structure | ||
|
||
The Server HTTP response headers should be defined mainly as [Array of Tables](https://toml.io/en/v1.0.0#array-of-tables). | ||
|
||
Each table entry should have two key/value pairs: | ||
|
||
- One `source` key containing an string *glob pattern*. | ||
- One `headers` key containing a [set or hash table](https://toml.io/en/v1.0.0#table) describing plain HTTP headers to apply. | ||
|
||
A particular set of HTTP headers can only be applied when a `source` matches against the request uri. | ||
|
||
!!! info "Custom HTTP headers take precedence over existing ones" | ||
Whatever custom HTTP header could **replace** an existing one if it was previously defined (E.g server default headers) and matches its `source`. | ||
|
||
The headers order is important since it determine its precedence. | ||
|
||
**Example:** if the feature `--cache-control-headers=true` is enabled but also a custom `cache-control` header was defined then the custom header will have priority. | ||
|
||
### Source | ||
|
||
Source is a [Glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) that should match against the uri that is requesting a resource file. | ||
|
||
### Headers | ||
|
||
A set of valid plain [HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers) to be applied. | ||
|
||
## Examples | ||
|
||
Below some examples of how to customize server HTTP headers in three variants. | ||
|
||
### Oneline version | ||
|
||
```toml | ||
[advanced] | ||
|
||
[[advanced.headers]] | ||
source = "**/*.{js,css}" | ||
headers = { Access-Control-Allow-Origin = "*", X-XSS-PROTECTION = "1; mode=block" } | ||
``` | ||
|
||
### Multiline version | ||
|
||
```toml | ||
[advanced] | ||
|
||
[[advanced.headers]] | ||
source = "*.html" | ||
[advanced.headers.headers] | ||
Cache-Control = "public, max-age=36000" | ||
Content-Security-Policy = "frame-ancestors 'self'" | ||
Strict-Transport-Security = "max-age=63072000; includeSubDomains; preload" | ||
``` | ||
|
||
### Multiline version with explicit header key (dotted) | ||
|
||
```toml | ||
[advanced] | ||
|
||
[[advanced.headers]] | ||
source = "**/*.{jpg,jpeg,png,ico,gif}" | ||
headers.Strict-Transport-Security = "max-age=63072000; includeSubDomains; preload" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters