> For the complete documentation index, see [llms.txt](https://docs.fortifiedid.se/resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fortifiedid.se/resources/resource.md).

# Resource

## Introduction

The Resource module publishes static files from a local directory over HTTP. Deploy multiple module instances when files must be served from different roots or HTTP contexts.

## Configuration

{% hint style="info" %}
**Module name:** `Resource`
{% endhint %}

{% tabs %}
{% tab title="Properties" %}

<table><thead><tr><th>Name</th><th>Description</th><th>Default</th><th data-type="checkbox">Mandatory</th></tr></thead><tbody><tr><td><code>http_context</code></td><td>Base HTTP context for the published files.</td><td><code>"/resources"</code></td><td>false</td></tr><tr><td><code>context_path</code></td><td>Route mounted below <code>http_context</code>.</td><td><code>"/"</code></td><td>false</td></tr><tr><td><code>webroot_dir</code></td><td>Local directory containing the files to publish.</td><td><code>""</code></td><td>true</td></tr><tr><td><code>overlay_dir</code></td><td>One overlay directory or an ordered array of overlay directories. Overlay files take precedence over files in <code>webroot_dir</code>.</td><td><code>[]</code></td><td>false</td></tr><tr><td><code>overlay_dirs</code></td><td>Compatibility name for additional overlay directories. Prefer <code>overlay_dir</code>.</td><td><code>[]</code></td><td>false</td></tr><tr><td><code>public</code></td><td>Allows requests without an authenticated session when enabled.</td><td><code>false</code></td><td>false</td></tr><tr><td><code>http_auth_redirect_url</code></td><td>Redirect target for unauthenticated requests when <code>public</code> is <code>false</code>.</td><td><code>""</code></td><td>false</td></tr><tr><td><code>enable_precompression</code></td><td>Serves matching pre-compressed files from <code>webroot_dir</code>.</td><td><code>false</code></td><td>false</td></tr><tr><td><code>enable_precompression_overlay</code></td><td>Serves matching pre-compressed files from overlay directories.</td><td><code>false</code></td><td>false</td></tr><tr><td><code>cache_control</code></td><td>Ordered cache policies. See <a href="#cache-control">Cache control</a>.</td><td>Directory responses are not cached</td><td>false</td></tr><tr><td><code>use_cache</code></td><td>Enables the static handler cache.</td><td><code>true</code></td><td>false</td></tr><tr><td><code>files_read_only</code></td><td>Enables file metadata caching when files do not change while the service is running.</td><td><code>true</code></td><td>false</td></tr><tr><td><code>cache_entry_timeout_ms</code></td><td>Lifetime of cached file metadata in milliseconds.</td><td><code>30000</code></td><td>false</td></tr><tr><td><code>max_age_secs</code></td><td>Browser cache lifetime for static files in seconds.</td><td><code>86400</code></td><td>false</td></tr></tbody></table>
{% endtab %}

{% tab title="Example" %}

```json
{
  "name": "Resource",
  "enabled": true,
  "config": {
    "http_context": "/assets",
    "context_path": "/public",
    "webroot_dir": "htdocs/public",
    "overlay_dir": [
      "htdocs/branding"
    ],
    "public": true,
    "enable_precompression": true
  }
}
```

{% endtab %}
{% endtabs %}

This example publishes files from `htdocs/public` at `/assets/public`. A matching file in `htdocs/branding` is served before the file in the web root.

## Pre-compressed resources

When pre-compression is enabled and the request contains an `Accept-Encoding` header, the module looks for a matching compressed file before serving the original file.

| Encoding | File extension |
| -------- | -------------- |
| Brotli   | `.br`          |
| Gzip     | `.gz`          |

Send `X-Precompressed-Content: false` to disable pre-compressed content for an individual request. A pre-compressed response includes these diagnostic headers:

```
X-Precompressed-Content: true
X-Precompressed-Path: <path-to-precompressed-file>
X-Precompressed-Encoding: <encoding>
```

## Cache control

Without a `cache_control` object, directory and index responses receive `Cache-Control: no-store, no-transform, max-age=0`. Static files otherwise use the static handler cache settings.

Policies are evaluated in order and the first matching glob pattern wins:

```json
{
  "cache_control": {
    "policies": [
      {
        "pattern": "**/*.html",
        "value": "no-store, no-transform, max-age=0",
        "override": true
      },
      {
        "pattern": "**",
        "value": "public, immutable, max-age=86400",
        "override": true
      }
    ]
  }
}
```

Set `override` to `false` when the policy should only add the header if no earlier handler has already set it.
