PrerenderOptions (@shadow-js/dusk/static)
Options of prerender.
Options of prerender.
Import#
ts
import type { PrerenderOptions } from "@shadow-js/dusk/static";
Signature#
ts
interface PrerenderOptions {
/** The handler that renders every page; the same one that serves production. */
readonly handler: Handler;
/** Directory the files are written to. */
readonly outDir: string;
/** Paths to render (`"/"`, `"/posts/1"`), or a function that lists them. */
readonly paths: readonly string[] | (() => readonly string[] | Promise<readonly string[]>);
/**
* Origin the handler is told it is served from. Default `"http://localhost"`, or, when the
* handler's `security.allowedHosts` does not list `localhost`, the first plain host it lists. A
* request the handler refuses because of the host fails with a message naming `allowedHosts`.
*/
readonly origin?: string;
/** `"directory"` writes `/about` as `about/index.html` (default); `"file"` as `about.html`. */
readonly format?: "directory" | "file";
/** Pages rendered at once. Default 4. */
readonly concurrency?: number;
/** Most pages one run renders. Default 10 000; more is an error. */
readonly maxPages?: number;
/** Largest page in bytes. Default 16 MiB. */
readonly maxPageBytes?: number;
/** Time one page may take, in milliseconds. Default 30 000. */
readonly pageTimeoutMs?: number;
/** Statuses that are written. Default `[200]`. Others fail the run, naming the path. */
readonly allowStatus?: readonly number[];
/** What to do with a redirect: `"error"` (default) fails; `"html"` writes a meta-refresh page. */
readonly onRedirect?: "error" | "html";
/**
* File name of the single-page-app shell (the document without route content), for hosts that
* serve it as the fallback. Default `"200.html"`; `false` skips it. Needs a handler from
* `createHandler` (it has `renderShell`).
*/
readonly shell?: string | false;
/**
* Path rendered for `404.html` (it should match no route). Default `"/__shadow_not_found__"`;
* `false` skips the file. A 404 answer is expected here.
*/
readonly notFoundPath?: string | false;
/** Headers added to every request, for example `accept-language`. */
readonly headers?: HeadersInit;
/**
* Follows the internal links of the rendered HTML pages: `true` for three hops and 500 added pages,
* or `{ depth, limit }` (depth at least 1, limit at least 0). Links to other origins, fragments,
* files (a last segment with a dot) and `/_dusk` are not followed. Off by default.
*/
readonly crawlLinks?: boolean | { readonly depth?: number; readonly limit?: number };
/** Keeps a path (listed or found by the crawl) out when it returns false. */
readonly filter?: (path: string) => boolean;
/** Attempts after a path that threw or answered 5xx. Default 0. */
readonly retry?: number;
/** Called after each page is written. */
readonly onSuccess?: (page: PrerenderedPage) => void | Promise<void>;
/** Called for each path that did not render, listed or found, before the run fails. */
readonly onError?: (failure: PrerenderFailure) => void | Promise<void>;
}
Members#
| Name | Type | Description |
|---|---|---|
handler |
readonly handler: Handler |
The handler that renders every page; the same one that serves production. |
outDir |
readonly outDir: string |
Directory the files are written to. |
paths |
readonly paths: readonly string[] | (() => readonly string[] | Promise<readonly string[]>) |
Paths to render ("/", "/posts/1"), or a function that lists them. |
origin? |
readonly origin?: string |
Origin the handler is told it is served from. Default "http://localhost", or, when the handler's security.allowedHosts does not list localhost, the first plain host it lists. A request the handler refuses because of the host fails with a message naming allowedHosts. |
format? |
readonly format?: "directory" | "file" |
"directory" writes /about as about/index.html (default); "file" as about.html. |
concurrency? |
readonly concurrency?: number |
Pages rendered at once. Default 4. |
maxPages? |
readonly maxPages?: number |
Most pages one run renders. Default 10 000; more is an error. |
maxPageBytes? |
readonly maxPageBytes?: number |
Largest page in bytes. Default 16 MiB. |
pageTimeoutMs? |
readonly pageTimeoutMs?: number |
Time one page may take, in milliseconds. Default 30 000. |
allowStatus? |
readonly allowStatus?: readonly number[] |
Statuses that are written. Default [200]. Others fail the run, naming the path. |
onRedirect? |
readonly onRedirect?: "error" | "html" |
What to do with a redirect: "error" (default) fails; "html" writes a meta-refresh page. |
shell? |
readonly shell?: string | false |
File name of the single-page-app shell (the document without route content), for hosts that serve it as the fallback. Default "200.html"; false skips it. Needs a handler from createHandler (it has renderShell). |
notFoundPath? |
readonly notFoundPath?: string | false |
Path rendered for 404.html (it should match no route). Default "/__shadow_not_found__"; false skips the file. A 404 answer is expected here. |
headers? |
readonly headers?: HeadersInit |
Headers added to every request, for example accept-language. |
crawlLinks? |
readonly crawlLinks?: boolean | { readonly depth?: number; readonly limit?: number } |
Follows the internal links of the rendered HTML pages: true for three hops and 500 added pages, or { depth, limit } (depth at least 1, limit at least 0). Links to other origins, fragments, files (a last segment with a dot) and /_dusk are not followed. Off by default. |
filter? |
readonly filter?: (path: string) => boolean |
Keeps a path (listed or found by the crawl) out when it returns false. |
retry? |
readonly retry?: number |
Attempts after a path that threw or answered 5xx. Default 0. |
onSuccess? |
readonly onSuccess?: (page: PrerenderedPage) => void | Promise<void> |
Called after each page is written. |
onError? |
readonly onError?: (failure: PrerenderFailure) => void | Promise<void> |
Called for each path that did not render, listed or found, before the run fails. |