index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2022-07-06 20:20:31.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2022-07-06 20:20:31.0 +00:00:00
commit
37c9ffc56b568aaadd0885268f2cb17292973bff [patch]
tree
b3380a68e46879ec61a86a3536219272a3db87b6
parent
5163564817b5e9ee058a1bf83e680a13bd983fc2
download
37c9ffc56b568aaadd0885268f2cb17292973bff.tar.gz

docs: url rewrites feature [skip ci]



Diff

 docs/content/features/url-rewrites.md | 41 ++++++++++++++++++++++++++++++++++++-
 docs/mkdocs.yml                       |  1 +-
 2 files changed, 42 insertions(+)

diff --git a/docs/content/features/url-rewrites.md b/docs/content/features/url-rewrites.md
new file mode 100644
index 0000000..47d99ea
--- /dev/null
+++ b/docs/content/features/url-rewrites.md
@@ -0,0 +1,41 @@
# URL Rewrites 

**SWS** provides the ability to rewrite request URLs with pattern matching support.

URI rewrites are particularly useful with pattern matching ([globs]https://en.wikipedia.org/wiki/Glob_(programming)), as the server can accept any URL that matches the pattern and let the client-side code decide what to display.

## Structure

The URL rewrite rules should be defined mainly as an [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 a string _glob pattern_.
- One `destination` string containing the local file path.

!!! info "Note"
    The incoming request(s) will reach the `destination` only if the request(s) URI matches the `source` pattern.

### Source

The source is a [Glob pattern]https://en.wikipedia.org/wiki/Glob_(programming) that should match against the URI that is requesting a resource file.

### Destination

A local file path which must exist. It has to look something like `/some/directory/file.html`. It is worth noting that the `/` at the beginning indicates the server's root directory.

## Examples

```toml
[advanced]

### URL Rewrites

[[advanced.rewrites]]
source = "**/*.{png,ico,gif}"
destination = "/assets/generic1.png"

[[advanced.rewrites]]
source = "**/*.{jpg,jpeg}"
destination = "/images/generic2.png"
```
diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml
index 42e4759..72f9399 100644
--- a/docs/mkdocs.yml
+++ b/docs/mkdocs.yml
@@ -139,6 +139,7 @@ nav:
    - 'Worker Threads Customization': 'features/worker-threads.md'
    - 'Error Pages': 'features/error-pages.md'
    - 'Custom HTTP Headers': 'features/custom-http-headers.md'
    - 'URL Rewrites': 'features/url-rewrites.md'
    - 'Windows Service': 'features/windows-service.md'
  - 'Platforms & Architectures': 'platforms-architectures.md'
  - 'Migration from v1 to v2': 'migration.md'