[]previous and next page

rewrite

Returns a rewrite answer for middleware: return rewrite("/internal/path").

Returns a rewrite answer for middleware: return rewrite("/internal/path").

Import#

ts
import { rewrite } from "@shadow-js/dusk/server";

Signature#

ts
function rewrite(destination: string, options: RewriteOptions = {}): Response

Parameters#

Name Description
destination A path of this app, optionally with a query string (/site/acme/index.html?x=1). Anything else is refused: an absolute URL, a protocol-relative //host, a backslash, a control character, or a path under /_dusk/.
options The request headers the target receives.

Returns#

A response that only the handler reads. Return it from middleware, unchanged, so the handler sees it.

Throws#

  • TypeError for a destination that is not a path of this app.

Examples#

ts
export const middleware: Middleware[] = [
  (event, next) => (event.url.hostname === "status.example.com" ? rewrite("/status") : next()),
];