[]previous and next page

workerSource

The Worker module the adapter writes.

The Worker module the adapter writes. Without a host list and without the file gate it is the plain handler (the assets binding serves files before the Worker runs). Otherwise the Worker runs for every request (run_worker_first = true):

  • a Host the list refuses goes to the handler, which answers its 400 (a file is never served for it);
  • a GET or HEAD for a listed Host, on a path no page rule takes, is looked up in the assets binding (a 404 from it falls through to the handler);
  • with the file gate (runMiddlewareForStaticFiles), a file the binding has goes through the handler's gateAsset first: the middleware's refusal is sent, or the file is sent with the headers and cookies the middleware set;
  • a prerendered page a rule applies to goes to the handler, never to its file (B2). The page key mirrors pageKeyOf (shared/static-page.ts); a test pins the two together.

Import#

ts
import { workerSource } from "@shadow-js/dusk/cloudflare";

Signature#

ts
function workerSource(input: {
  readonly serverFile: string;
  readonly allowedHosts?: readonly string[];
  readonly handlerPages: readonly string[];
  /** The handler runs its middleware for files (`runMiddlewareForStaticFiles`): every file goes through its gate. */
  readonly gateFiles?: boolean;
}): string

Parameters#

Name Description
input The server bundle's path from the output folder, the host list, the pages the handler answers, and whether the middleware runs for files.

Returns#

The module source.