basalt / tenancy/src / tryNormalizeDomain
Function: tryNormalizeDomain()
> tryNormalizeDomain(input): string | null
Defined in: tenancy/src/custom-domains.ts:52
Canonicalize a domain/Host value, or return null when it is not a hostname.
Lowercases, trims, strips an optional :port and trailing dots, then holds what is left to the RFC 1123 hostname grammar: dot-separated labels of [a-z0-9-], at most 253 characters, with a last label that is not all digits. Anything else is rejected, not rewritten — userinfo (acme.app.com@evil.com), a path, percent-encoding, full-width or other non-ASCII characters, IPv4/IPv6 literals. A URL parser would "helpfully" turn several of those into a different host than the one a proxy, WAF or cache in front of the app routed on.
Internationalized domains must be given in their ASCII (xn--) form, which is what browsers send in Host; convert user input with domainToASCII() from node:url before registering it.
Parameters
input
string
Returns
string | null