From 77aaa558153b626ecca4b6d73d686f3e55f65ae3 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 31 Oct 2017 08:48:52 +0530 Subject: [PATCH] Working on static server --- index.js | 21 +++++---------------- util/validate.js | 11 ++++++----- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 581cb73..7e493f4 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ var validate = require('./util/validate') // Requiring Actions var createProxyServer = require('./actions/createProxyServer') +var createStaticServer = require('./actions/createStaticServer') // Using Validator // var isDomain = validator.isFQDN @@ -39,28 +40,16 @@ program program .command('static [outPort]') .description('Create a static server at this folder.') - .action(function(domain, outPort="80") { - if(!validate(domain, outPort)) - createStaticServer(domain, outPort) + .action(function(domain, outPort=80) { + if(!validate(domain, outPort)) return + console.log('Static server works') + //createStaticServer(domain, outPort) }) program .command('proxy [outPort]') .description('Create a proxy server, listening at port number.') .action(function(domain, inPort, outPort = "80") { - /* Removing this to make it modular - var validInPort = /^\d+$/.test(inPort) - var validOutPort = /^\d+$/.test(outPort) - if(!isDomain(domain)) { - console.log(domainInvalidMsg) - return } - if(!validInPort || !validOutPort) { - console.log(portInvalidMsg[0]) - return } - if(!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { - console.log(portInvalidMsg[1]) - return } - else { */ 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 d8a9408..54156ab 100644 --- a/util/validate.js +++ b/util/validate.js @@ -2,7 +2,7 @@ var validator = require('validator') // Using Validator var isDomain = validator.isFQDN -function validate(domain, inPort = undefined, outPort) { +function validate(domain, inPort = undefined, 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+$/.exec(inPort) @@ -12,22 +12,23 @@ function validate(domain, inPort = undefined, outPort) { console.log(domainInvalidMsg) return isTrue = false } - if (typeof outPort == undefined) { - if (!validInPort) { + if (typeof inPort == undefined) { + if (!validOutPort) { console.log(portInvalidMsg[0]) return isTrue = false } - if (!(validInPort > 0 && validInPort <= 65535)) { + if (!(validOutPort > 0 && validOutPort <= 65535)) { console.log(portInvalidMsg[1]) return isTrue = false } } - if (typeof outPort !== undefined) { + if (typeof inPort !== undefined) { if (!validInPort || !validOutPort) { console.log(portInvalidMsg[0]) return isTrue = false } if (typeof outPort !== undefined) { + console.log(validInPort) if (!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { console.log(portInvalidMsg[1]) return isTrue = false