From d6cad7cb65a23153077f23efdb1d81268b768d86 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Mon, 5 Jun 2017 11:20:58 -0600 Subject: [PATCH] added support for wildcard domains --- wsclient.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wsclient.js b/wsclient.js index f4b540c..6874aaa 100644 --- a/wsclient.js +++ b/wsclient.js @@ -202,7 +202,26 @@ function run(copts) { 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 = { port: port , host: '127.0.0.1'