1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/src/utils/matchHostname.js

20 lines
620 B
JavaScript

function matchHostname(hostname, reqHostname) {
if (typeof hostname == "undefined" || hostname == "*") {
return true;
} else if (reqHostname && hostname.indexOf("*.") == 0 && hostname != "*.") {
const hostnamesRoot = hostname.substring(2);
if (
reqHostname == hostnamesRoot ||
(reqHostname.length > hostnamesRoot.length &&
reqHostname.indexOf("." + hostnamesRoot) ==
reqHostname.length - hostnamesRoot.length - 1)
) {
return true;
}
} else if (reqHostname && reqHostname == hostname) {
return true;
}
return false;
}
module.exports = matchHostname;