Skip to content

Static Files

Serve static files from any filesystem using http.static. Static handlers mount directly on the server and can serve SPAs, assets, or user uploads from any path.

- name: static
kind: http.static
meta:
server: gateway
path: /
fs: app:public
static_options:
spa: true
index: index.html
cache: "public, max-age=3600"
FieldTypeDescription
meta.serverRegistry IDParent HTTP server
pathstringURL mount path (must start with /)
fsRegistry IDFilesystem entry to serve from
static_options.spaboolSPA mode - serve index for unmatched paths
static_options.indexstringIndex file (required when spa=true)
static_options.cachestringCache-Control header value
middleware[]stringMiddleware chain
optionsmapMiddleware options (dot notation)
Static handlers can be mounted to any path on the server. Multiple handlers can coexist—mount assets at /static and an SPA at /.

Static files are served from filesystem entries. Any filesystem type works:

entries:
# Local directory
- name: public
kind: fs.directory
directory: ./public
# Static handler
- name: static
kind: http.static
meta:
server: gateway
path: /static
fs: public

Request /static/css/style.css serves ./public/css/style.css.

To serve a subdirectory, point the fs reference at a filesystem entry rooted there—for example an fs.directory with directory: set to the subdirectory:

entries:
- name: content
kind: fs.directory
directory: ./app/documentation/html
- name: docs
kind: http.static
meta:
server: gateway
path: /docs
fs: content

Single Page Applications need all routes to serve the same index file for client-side routing:

- name: spa
kind: http.static
meta:
server: gateway
path: /
fs: app:frontend
static_options:
spa: true
index: index.html
RequestResponse
/app.jsServes app.js (file exists)
/users/123Serves index.html (SPA fallback)
/api/dataServes index.html (SPA fallback)
When spa: true, the index file is required. Existing files are served directly; all other paths return the index file.

Set appropriate caching for different asset types:

entries:
- name: app_fs
kind: fs.directory
directory: ./dist
# Versioned assets - cache forever
- name: assets
kind: http.static
meta:
server: gateway
path: /assets
fs: app_fs
static_options:
cache: "public, max-age=31536000, immutable"
# HTML - short cache, must revalidate
- name: app
kind: http.static
meta:
server: gateway
path: /
fs: app_fs
static_options:
spa: true
index: index.html
cache: "public, max-age=0, must-revalidate"

Common cache patterns:

  • Versioned assets: public, max-age=31536000, immutable
  • HTML/index: public, max-age=0, must-revalidate
  • User uploads: private, max-age=3600

Apply middleware for compression, CORS, or other processing:

- name: static
kind: http.static
meta:
server: gateway
path: /
fs: app:public
middleware:
- compress
- cors
options:
compress.level: "best"
cors.allow.origins: "*"

Middleware wraps the static handler in order—requests pass through each middleware before reaching the file server.

Path matching is prefix-based. A handler at / catches all unmatched requests. Use routers for API endpoints to avoid conflicts.