Skip to content

Auto-registered Layers & Services ​

Sword can automatically register common Tower layers and services through configuration alone, via toml. When the corresponding feature is compiled, the layer is registered automatically: it uses the values from its section when present, and the defaults otherwise. No manual registration is needed.

Compression ​

Enable response compression with the [compression] section:

toml
[compression]
algorithms = ["gzip", "br"]

The algorithms key accepts a list of these algorithms:

AlgorithmNote
gzipWidely supported
brBrotli, best compression ratio
deflateLegacy algorithm
zstdFast, modern algorithm

CORS ​

Configure Cross-Origin Resource Sharing with the [cors] section:

toml
[cors]
allow-origins = ["*"]
allow-methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"]

The available options are:

OptionDescription
allow-originsList of allowed origins or ["*"] for all
allow-methodsHTTP methods to allow
allow-headersCustom allowed headers
allow-credentialsEnables credentials sharing
max-ageSeconds to cache the preflight response

Static file serving ​

Serve a directory of static files with the [serve-dir] section:

toml
[serve-dir]
static-dir = "public"
router-path = "/static"
KeyDescriptionDefault
static-dirDirectory to serve"public"
router-pathURL path prefix"/static"
compression-algorithmPre-compressed file support (br, gzip, deflate, zstd)—
chunk-sizeStreaming chunk size (e.g. "64KB")—
not-found-fileCustom 404 fallback file—

How they are registered ​

When Sword loads the configuration, it automatically registers the corresponding Tower layers or services in the correct order before the application starts, using each section's values when present and its defaults otherwise. No manual setup is required.