Tengo que obtener un nombre de host sin sufijo y sin subdominio.
Exp:
URL: https://my-domain.com URL2: https://my-domain.store.comEntonces, solo necesito mi dominio, ¿cómo puedo obtener esto?
echa un vistazo a esto
const url = new URL('http://example.com/path/index.html?param=value'); console.log(url.hostname) // gives example.comy si tiene un subdominio:
function getDomain(hostname) { hostname = hostname.split('.'); hostname.reverse(); return `${hostname[1]}.${hostname[0]}`; } url = new URL('http://test.example.com/path/index.html?param=value'); getDomain(url.hostname) // gives example.com url = new URL('http://example.com/path/index.html?param=value'); getDomain(url.hostname) // gives example.comtomado de aquí