added support for wildcard domains

This commit is contained in:
tigerbot 2017-06-05 11:20:58 -06:00
parent e6da8277c4
commit d6cad7cb65
1 changed files with 20 additions and 1 deletions

View File

@ -202,7 +202,26 @@ function run(copts) {
return; return;
} }
port = portList[servername] || portList['*']; port = portList[servername];
if (!port) {
// Check for any wildcard domains, sorted longest to shortest so the one with the
// biggest natural match will be found first.
Object.keys(portList).filter(function (pattern) {
return pattern[0] === '*' && pattern.length > 1;
}).sort(function (a, b) {
return b.length - a.length;
}).some(function (pattern) {
var subPiece = pattern.slice(1);
if (subPiece === servername.slice(-subPiece.length)) {
port = portList[pattern];
return true;
}
});
}
if (!port) {
port = portList['*'];
}
var createOpts = { var createOpts = {
port: port port: port
, host: '127.0.0.1' , host: '127.0.0.1'