//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){
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.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.exit(1);
}
}
// Throw if Nginx is not found
// Throw if Nginx is not found
if(!shell.which('nginx')){
if(!shell.which('nginx')){
shell.echo('I need nginx to work. Install nginx first. https://nginx.org/')
shell.echo('I need nginx to work. Install nginx first. https://nginx.org/');
shell.exit(1)
shell.exit(1);
}
}
*/
*/
@ -40,20 +38,19 @@ program
program
program
.command('static <domain> [outPort]')
.command('static <domain> [outPort]')
.description('Create a static server at this folder.')
.description('Create a static server at this folder.')
.action(function(domain,outPort=80){
.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
if(!validate(domain,outPort))return//Validates domain and outport, and if invalid, throws and returns.
//createStaticServer(domain, outPort)
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!")
console.log("Done! Your static server has been set up!\nPoint your domain to this server and check "+chalk.cyan(domain)+" to verify!")
})
})
program
program
.command('proxy <domain> <inPort> [outPort]')
.command('proxy <domain> <inPort> [outPort]')
.description('Create a proxy server, listening at port number.')
.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
if(!validate(domain,inPort,outPort))return
createProxyServer(domain,inPort,outPort)
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!")
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
program
@ -71,11 +68,12 @@ program
})
})
program
program
.command('*')
.command('*')// This should pick invalid commands, but it doesn't, yet.
.action(function(){
.action(function(){
console.log("Invalid command. Type "+chalk.cyan('up --help')+" for help.")
console.log("Invalid command. Type "+chalk.cyan('up --help')+" for help.")
})
})
// Adds custom help text to the automatically generated help.
program.on('--help',function(){
program.on('--help',function(){
console.log('');
console.log('');
console.log(' Usage:');
console.log(' Usage:');
@ -88,4 +86,5 @@ program.on('--help', function () {
console.log('');
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;
varvalidInPort=parseToInt(inPort)
// Error messages
varvalidOutPort=parseToInt(outPort)
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."];
varisValid=true
// 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;
}
// Throw if input is not a Fully Qualified Domain Name (FQDN)
if(!isDomain(domain)){
if(!isDomain(domain)){
console.log(domainInvalidMsg)
console.log(domainInvalidMsg[1]);
returnisValid=false
returnisValid=false;
}
}
// Enter if `inPort` is not defined. This happens for `up static` where no inbound ports are required.
if(typeofinPort==undefined){
if(typeofinPort==undefined){
if(!validOutPort){
if(!validOutPort){
console.log(portInvalidMsg[0])
console.log(portInvalidMsg[0]);// `outPort` is not an integer.
returnisValid=false
returnisValid=false;
}
}
if(!(validOutPort>0&&validOutPort<=65535)){
if(!(validOutPort>0&&validOutPort<=65535)){
console.log(portInvalidMsg[1])
console.log(portInvalidMsg[1]);// `outPort` is not within port range.
returnisValid=false
returnisValid=false;
}
}
}
}
// Enter if `inPort` is defined. This happens for `up proxy` where inbound port is required.
if(typeofinPort!==undefined){
if(typeofinPort!==undefined){
if(!validInPort||!validOutPort){
if(!validInPort||!validOutPort){
console.log(portInvalidMsg[0])
console.log(portInvalidMsg[0]);// Either `inPort` or `outPort` is not an integer.