StaticOptions
Options of static file serving.
Options of static file serving.
Import#
ts
import type { StaticOptions } from "@shadow-js/dusk/node";
Signature#
ts
interface StaticOptions {
/** Directory to serve (the client build output). */
readonly dir: string;
/** URL prefix the directory is mounted at. Default `"/"`. */
readonly prefix?: string;
/**
* Which files get `Cache-Control: public, max-age=31536000, immutable`. Receives the path
* relative to `dir`. Default: files whose name carries a content hash (`app-3f9a1c2e.js`).
*/
readonly immutable?: (relativePath: string) => boolean;
/** The build's assets folder (Vite's `build.assetsDir`), used by the default `immutable` test. Default `"assets"`. */
readonly assetsDir?: string;
/** `Cache-Control` max-age of other files, in seconds. They always revalidate with an ETag. Default 0. */
readonly maxAgeSeconds?: number;
/** Name served for a directory request (`"index.html"` for a static site). Default: none. */
readonly index?: string | false;
/** Extensions tried for a path without one (`[".html"]` serves `/about` from `about.html`). */
readonly extensions?: readonly string[];
/** `"deny"` (default) never serves a path with a segment that starts with a dot, except the allowlisted `/.well-known/<name>` files. */
readonly dotfiles?: "allow" | "deny";
/** Use `.br` / `.zst` / `.gz` files next to the original when the client accepts them. Default `true`. */
readonly precompressed?: boolean;
/**
* Names served from `/.well-known/<name>` as plain files (one name each, no subpaths). Any other dotted path, and
* `.env*` in particular, stays denied. Default {@link WELL_KNOWN_NAMES}.
*/
readonly wellKnown?: readonly string[];
/**
* The prerendered pages and how each is answered (see {@link StaticPage}). A `handler` page is never served from its
* file: the request goes to the handler. A `static` page is served with its headers, and with the HSTS header when the
* request came over https. Default: none.
*/
readonly pages?: readonly StaticPage[];
}
Members#
| Name | Type | Description |
|---|---|---|
dir |
readonly dir: string |
Directory to serve (the client build output). |
prefix? |
readonly prefix?: string |
URL prefix the directory is mounted at. Default "/". |
immutable? |
readonly immutable?: (relativePath: string) => boolean |
Which files get Cache-Control: public, max-age=31536000, immutable. Receives the path relative to dir. Default: files whose name carries a content hash (app-3f9a1c2e.js). |
assetsDir? |
readonly assetsDir?: string |
The build's assets folder (Vite's build.assetsDir), used by the default immutable test. Default "assets". |
maxAgeSeconds? |
readonly maxAgeSeconds?: number |
Cache-Control max-age of other files, in seconds. They always revalidate with an ETag. Default 0. |
index? |
readonly index?: string | false |
Name served for a directory request ("index.html" for a static site). Default: none. |
extensions? |
readonly extensions?: readonly string[] |
Extensions tried for a path without one ([".html"] serves /about from about.html). |
dotfiles? |
readonly dotfiles?: "allow" | "deny" |
"deny" (default) never serves a path with a segment that starts with a dot, except the allowlisted /.well-known/<name> files. |
precompressed? |
readonly precompressed?: boolean |
Use .br / .zst / .gz files next to the original when the client accepts them. Default true. |
wellKnown? |
readonly wellKnown?: readonly string[] |
Names served from /.well-known/<name> as plain files (one name each, no subpaths). Any other dotted path, and .env* in particular, stays denied. Default WELL_KNOWN_NAMES. |
pages? |
readonly pages?: readonly StaticPage[] |
The prerendered pages and how each is answered (see StaticPage). A handler page is never served from its file: the request goes to the handler. A static page is served with its headers, and with the HSTS header when the request came over https. Default: none. |