( optionsHost: string | boolean | undefined, )
| 962 | } |
| 963 | |
| 964 | export async function resolveHostname( |
| 965 | optionsHost: string | boolean | undefined, |
| 966 | ): Promise<Hostname> { |
| 967 | let host: string | undefined |
| 968 | if (optionsHost === undefined || optionsHost === false) { |
| 969 | // Use a secure default |
| 970 | host = 'localhost' |
| 971 | } else if (optionsHost === true) { |
| 972 | // If passed --host in the CLI without arguments |
| 973 | host = undefined // undefined typically means 0.0.0.0 or :: (listen on all IPs) |
| 974 | } else { |
| 975 | host = optionsHost |
| 976 | } |
| 977 | |
| 978 | // Set host name to localhost when possible |
| 979 | let name = host === undefined || wildcardHosts.has(host) ? 'localhost' : host |
| 980 | |
| 981 | if (host === 'localhost') { |
| 982 | // See #8647 for more details. |
| 983 | const localhostAddr = await getLocalhostAddressIfDiffersFromDNS() |
| 984 | if (localhostAddr) { |
| 985 | name = localhostAddr |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | return { host, name } |
| 990 | } |
| 991 | |
| 992 | export function extractHostnamesFromCerts( |
| 993 | certs: HttpsServerOptions['cert'] | undefined, |
no test coverage detected