🐑 Commons Host



Host Options

Table of Contents


Default: '' or 'localhost' (only for the default site, see serveDefaultSite)

The DNS hostname of the site. May be specified as an Internationalized Domain Name (IDN) containing non-ASCII characters.


  hosts: [
    { domain: 'example.net' },
    { domain: 'xn--yfro4i67o.example.net' },
    { domain: '🦄.example.net' }


The path to the base directory containing static files to serve.

If no root is specified, the server tries to auto-detect static site generator or packaging tool output directories. For example: ./dist, ./public, ./_site, and many more.

If no directory is auto-detected, the current working directory is used. A warning message is logged to indicate this fallback behaviour.


Default: {} (no fallback)

An object mapping HTTP status code to file paths.

Fallbacks are supported for:


  fallback: {
    200: './index.html'


Sets the HTTP caching headers.


Default: []

An array of path globs for immutable files.

Special named patterns can be used as shorthand. These are:

By default, all non-immutable responses have the header:

cache-control: public, max-age=1, must-revalidate

File paths that match the patterns set by the cacheControl.immutable option are considered to never, ever change their contents. To tell browsers never to revalidate these resources, they are served with the header:

cache-control: public, max-age=31536000, immutable


  cacheControl: {
    immutable: [


Behaviour of directory paths.


Default: 'always'

Enforces a consistent clean URL for directory paths.

The value is a string that can be:


Settings related to CORS.


Default: '*'

If specified, sets this value as the access-control-allow-origin header on every response.


Settings related to service workers.


Default: '/'

If specified, sets this value as the service-worker-allowed header on every response.


Settings related to HTTP Strict Transport Security.


Default: 5184000 (60 days)

Sets this value as the strict-transport-security header on every response.


The manifest property declares which files or URLs need to be pushed as dependencies for any request. Using HTTP/2 Server Push (PUSH_PROMISE frames) can eliminate round trips between browser and server and speed up resource loading.

The manifest property type can be:

Example: Inline manifest

  hosts: [
    domain: 'localhost',
    root: './dist',
    manifest: [
      // Example:
        // When serving the homepage,
        get: '**/*.html',
        // push all CSS and JS files.
        push: ['**/*.css', '**/*.js']

Example: External manifest file

Using an external file is useful when using a build tool that traces dependencies to automatically generate the manifest.

This example shows a static website in the ./dist directory. The first section runs the @commonshost/manifest command line interface (CLI) tool to trace all HTML/JS/CSS files for dependencies. The automatically generated manifest is stored as ./manifest. The second section shows a reference to this external manifest.

$ npx @commonshost/manifest generate ./dist ./manifest.json
  hosts: [{
    manifest: './manifest.json'