From e3fbd768a2e7b6fa813fb38b95b946b65146fd38 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'