//Throw if OS is not Linux or BSD. This should be changed to throw if not Debian based distro. Eventually, we can add more exceptions as `up` handles more cases.
if(!isLin){
shell.echo("\nThis is not a Linux or freeBSD distribution. I'm not written for this distro. Please raise an issue at "+chalk.cyan("https://github.com/codefeathers/up-serve")+" if you want `up` to be ported for your distro")
shell.exit(1)
shell.echo("\nThis is not a Linux or freeBSD distribution. I'm not written for this distro. Please raise an issue at "+chalk.cyan("https://github.com/codefeathers/up-serve")+" if you want `up` to be ported for your distro");
shell.exit(1);
}
//Throw if Nginx is not found
//Throw if Nginx is not found
if(!shell.which('nginx')){
shell.echo('I need nginx to work. Install nginx first. https://nginx.org/')
shell.exit(1)
shell.echo('I need nginx to work. Install nginx first. https://nginx.org/');
shell.exit(1);
}
*/
@ -40,20 +38,19 @@ program
program
.command('static <domain> [outPort]')
.description('Create a static server at this folder.')
.action(function(domain,outPort=80){
if(!validate(domain,outPort))return
//createStaticServer(domain, outPort)
.action(function(domain,outPort=80){//If outport is not given, 80 is set as default. Later, change this default to reflect nginx's settings.
if(!validate(domain,outPort))return//Validates domain and outport, and if invalid, throws and returns.
createStaticServer(domain,outPort)
console.log("Done! Your static server has been set up!\nPoint your domain to this server and check "+chalk.cyan(domain)+" to verify!")
})
program
.command('proxy <domain> <inPort> [outPort]')
.description('Create a proxy server, listening at port number.')
.action(function(domain,inPort,outPort="80"){
.action(function(domain,inPort,outPort="80"){//Inbound port is necessary, but outbound is set to 80 by default. Again, will change this to reflect nginx's settings.
if(!validate(domain,inPort,outPort))return
createProxyServer(domain,inPort,outPort)
console.log("Done! Your reverse proxy server has been set up!\nPoint your domain to this server and check "+chalk.cyan(domain)+" to verify!")
//}
})
program
@ -71,11 +68,12 @@ program
})
program
.command('*')
.command('*')// This should pick invalid commands, but it doesn't, yet.
.action(function(){
console.log("Invalid command. Type "+chalk.cyan('up --help')+" for help.")
})
// Adds custom help text to the automatically generated help.
program.on('--help',function(){
console.log('');
console.log(' Usage:');
@ -88,4 +86,5 @@ program.on('--help', function () {
console.log('');
});
// Parses commands passed to `up` and chooses one of the above commands.
vardomainInvalidMsg="\nDomain is not valid. Please use a valid domain name."
varportInvalidMsg=["\nPort should be a number.","\nPort should be a number from 1 and 65535."]
//var validInPort = /^\d+$/.exec(inPort)[0]
//var validOutPort = /^\d+$/.exec(outPort)[0]
//var regex = /^\d+$/.exec(outPort);
//var validInPort = regex ? regex[0] : null;
// Error messages
vardomainInvalidMsg=["\nPlease use a domain name instead of an IP address.","\nDomain is not valid. Please use a valid domain name."];
varportInvalidMsg=["\nPort should be a number.","\nPort should be a number from 1 and 65535."];
varvalidInPort=parseToInt(inPort)
varvalidOutPort=parseToInt(outPort)
// ARGV returns a string as input. Port numbers should be parsed to int to validate them. If validation fails, these will return undefined and will fail the subsequent test.
varvalidInPort=parseToInt(inPort);
varvalidOutPort=parseToInt(outPort);
// The value of isInvalid will be returned back. If none of the `if`s are true, the default value `true` is returned `domain`, `inPort` and `outPort` are considered validated.
varisValid=true;
// Throw if IP is given instead of domain name.
if(isIP(domain)){
console.log(domainInvalidMsg[0]);
returnisValid=false;
}
varisValid=true
// Throw if input is not a Fully Qualified Domain Name (FQDN)
if(!isDomain(domain)){
console.log(domainInvalidMsg)
returnisValid=false
console.log(domainInvalidMsg[1]);
returnisValid=false;
}
// Enter if `inPort` is not defined. This happens for `up static` where no inbound ports are required.
if(typeofinPort==undefined){
if(!validOutPort){
console.log(portInvalidMsg[0])
returnisValid=false
console.log(portInvalidMsg[0]);// `outPort` is not an integer.
returnisValid=false;
}
if(!(validOutPort>0&&validOutPort<=65535)){
console.log(portInvalidMsg[1])
returnisValid=false
console.log(portInvalidMsg[1]);// `outPort` is not within port range.
returnisValid=false;
}
}
// Enter if `inPort` is defined. This happens for `up proxy` where inbound port is required.
if(typeofinPort!==undefined){
if(!validInPort||!validOutPort){
console.log(portInvalidMsg[0])
returnisValid=false
console.log(portInvalidMsg[0]);// Either `inPort` or `outPort` is not an integer.