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

21 lines
620 B
JavaScript
Raw Normal View History

function matchHostname(hostname, reqHostname) {
2024-08-24 17:23:06 +02:00
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)
) {
2024-08-24 17:23:06 +02:00
return true;
}
2024-08-24 17:23:06 +02:00
} else if (reqHostname && reqHostname == hostname) {
return true;
}
return false;
}
2024-08-24 17:23:06 +02:00
module.exports = matchHostname;