[]previous and next page

compileHostRules

Compiles host patterns into a predicate.

Compiles host patterns into a predicate. A pattern is a host name (example.com), a host name with a port (example.com:8443) or a wildcard for subdomains (*.example.com, which does not match example.com itself). A pattern without a port matches any port. Matching is case-insensitive.

Import#

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

Signature#

ts
function compileHostRules(patterns: readonly string[]): (host: string) => boolean

Parameters#

Name Description
patterns The allowed hosts.

Returns#

A function from url.host to allowed or not.

Throws#

  • TypeError for an empty pattern or a bare *.

Examples#

ts
compileHostRules(["example.com", "*.example.com"])("api.example.com:443"); // true