@stacksjs/rpx
Version:
A modern and smart reverse proxy.
24 lines (23 loc) • 1.13 kB
TypeScript
/**
* Host-based route matching with wildcard support.
*
* The routing table is keyed by host pattern. A pattern is either an exact
* hostname (`api.example.com`) or a wildcard (`*.example.com`). Lookup prefers
* an exact match, then the most-specific (deepest-suffix) wildcard.
*
* Kept dependency-free and pure so it's reusable from both the daemon and the
* in-process multi-proxy path, and trivially unit-testable.
*/
export declare function isWildcardPattern(pattern: string): boolean;
/**
* True if `hostname` matches the wildcard `pattern` (`*.suffix`). A wildcard
* matches exactly one or more leading labels — `*.example.com` matches
* `a.example.com` and `a.b.example.com`, but NOT the bare apex `example.com`.
*/
export declare function matchesWildcard(hostname: string, pattern: string): boolean;
/**
* Find the route value for `hostname` in a host-keyed map. Exact match wins;
* otherwise the matching wildcard with the longest (most-specific) suffix wins.
* Returns `undefined` when nothing matches.
*/
export declare function matchHost<T>(table: Map<string, T>, hostname: string): T | undefined;