From 1844c77fb04fd2ac4782314dd03b2e829c29e00c Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 31 Oct 2017 07:12:13 +0530 Subject: [PATCH] Fixed regexp that caused output to be true instead of value --- index.js | 5 +---- util/validate.js | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index d02dda7..8ad747c 100644 --- a/index.js +++ b/index.js @@ -61,10 +61,7 @@ program console.log(portInvalidMsg[1]) return } else { */ - if (!validate(domain, inPort, outPort)) { - console.log("I should get printed if I'm not validated") - return - } + if (!validate(domain, inPort, outPort)) return createProxyServer(domain, inPort, outPort) console.log("Done! Your server has been set up!\nPoint your domain to this server and check " + chalk.cyan(domain) + " to verify!") //} diff --git a/util/validate.js b/util/validate.js index c2b1d9b..6a244f8 100644 --- a/util/validate.js +++ b/util/validate.js @@ -1,4 +1,3 @@ - var validator = require('validator') // Using Validator var isDomain = validator.isFQDN @@ -6,8 +5,8 @@ var isDomain = validator.isFQDN function validate(domain, inPort, outPort = undefined) { var domainInvalidMsg = "\nDomain is not valid. Please use a valid domain name." var portInvalidMsg = ["\nPort should be a number.", "\nPort should be a number from 1 and 65535."] - var validInPort = /^\d+$/.test(inPort) - var validOutPort = /^\d+$/.test(outPort) + var validInPort = /^\d+$/.exec(inPort) + var validOutPort = /^\d+$/.exec(outPort) var isTrue = true if (!isDomain(domain)) { console.log(domainInvalidMsg) @@ -22,12 +21,14 @@ function validate(domain, inPort, outPort = undefined) { console.log(portInvalidMsg[1]) return isTrue = false } - } + } /* if (typeof outPort !== undefined) { if (!validInPort || !validOutPort) { console.log(portInvalidMsg[0]) return isTrue = false } + } */ + if (typeof outPort !== undefined) { if (!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { console.log(portInvalidMsg[1]) return isTrue = false