Reference / @open-music-sdk/core / isOnHost
Function: isOnHost()
function isOnHost(url, hosts): boolean;Defined in: packages/core/src/hosts.ts:51
Whether url is https on one of hosts or on a subdomain of one, with no port and no credentials. The URL is read by the parser a browser reads it with, so what is checked is what will be requested. One that does not stand on its own, such as a relative one, is on no host that could be allowed.
It is read twice: on its own, and as a page that is https itself reads it. https:host/a and https:/host/a are whole URLs on their own and name host, but such a page reads them as paths on its own host, and asks there. A URL that the two readings take to different places is on no host that could be allowed.
It answers whatever it is asked, since other packages call it: what is no string is on no host, and neither is anything when hosts is no list. A name in the list that is no host name, as hostsOf holds one to be, allows nothing: an empty one would otherwise allow every host written with a dot at its end.
Parameters
url
string
The URL to check, as it will be requested.
hosts
readonly string[]
The host names allowed, as hostsOf gives them.
Returns
boolean
Whether url is https, with no port and no credentials, on one of hosts or a subdomain of one.