absoluteUrl
A full, absolute URL for a path: the base is metadataBase when given, else the origin of the request (or of the origin string or URL passed).
A full, absolute URL for a path: the base is metadataBase when given, else the origin of the request (or of the
origin string or URL passed). A path starting with / is taken from the origin, as in the URL standard. A query
string stays; a fragment is dropped, because a canonical or a shared link carries none. The trailing slash follows
trailingSlash, and the bare root is written as the origin (no slash), as the canonical is.
Import#
ts
import { absoluteUrl } from "@shadow-js/dusk/server";
Signature#
ts
function absoluteUrl(
path: string,
source: RequestEvent | string | URL,
options: AbsoluteUrlOptions = {},
): string
Parameters#
| Name | Description |
|---|---|
path |
A path (/about), a relative path, or an absolute http(s) URL (returned with the same rules). |
source |
The request event, or an origin string or URL, used when there is no metadataBase. |
options |
metadataBase and trailingSlash. |
Returns#
The absolute URL, on the base's scheme (https for a production origin).
Throws#
- TypeError when the base or the result is not an absolute http(s) URL.
Examples#
ts
absoluteUrl("/about", event); // "https://example.com/about" when the request is for example.com
absoluteUrl("/about", event, { metadataBase: "https://example.com", trailingSlash: "always" }); // "https://example.com/about/"