@ -32,8 +32,11 @@ function createProxyServer(domain, inPort, outPort) {
"}"
);
shell.mkdir('-p',npath.confD());
shell.mkdir('-p',npath.enabledSites());// Creates directories if doesn't exist
shell.ln('-sf',conf(npath.confD(),domain,outPort),conf(npath.enabledSites(),domain,outPort));// Symlink the conf file from sites-available to sites-enabled
// Check for requirements such as OS version and nginx install. Throw and exit if requirements not found.
// Check for requirements such as OS version and nginx install.
// Throw and exit if requirements not found.
// #Roadmap: Add ability to satisfy any possible requirements.
requirements();// Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up`
requirements();// Comment in development and uncomment this line in production.
// This should check whether the OS is compatible with this version of `up`
program
.version('0.1.5');
@ -29,23 +33,40 @@ program
program
.command('static <domain> [outPort]')
.description('Create a static server at this folder.')
.action(function(domain,outPort){//If outport is not given, 80 is set as default. Later, change this default to reflect nginx's settings.
outPort=outPort||"80";// This is a string because regex needs to validate it.
if(!validate(domain,outPort))return;//Validates domain and outport, and if invalid, throws and returns.
.action(function(domain,outPort){
// If outport is not given, 80 is set as default.
// Later, change this default to reflect nginx's settings.
outPort=outPort||"80";
// This is a string because regex needs to validate it.
if(!validate(domain,outPort))return;
// Validates domain and outport, and if invalid, throws and returns.
console.log("\nDone! Your static server has been set up!\nPoint your domain to this server and check "+chalk.cyan(domain)+" to verify!");
console.log(EOL+[
"Done! Your static server has been set up!",
"Point your domain to this server and check "+
chalk.cyan(domain)+
" to verify!"
].join(EOL));
});
program
.command('proxy <domain> <inPort> [outPort]')
.description('Create a proxy server, listening at port number.')
.action(function(domain,inPort,outPort){//Inbound port is necessary, but outbound is set to 80 by default. Again, will change this to reflect nginx's settings.
outPort=outPort||"80";// This is a string because regex needs to validate it.
.action(function(domain,inPort,outPort){
// Inbound port is necessary, but outbound is set to 80 by default.
// Again, will change this to reflect nginx's settings.
outPort=outPort||"80";
// This is a string because regex needs to validate it.
// 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.
// 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. This tool 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");
@ -12,14 +14,26 @@ function validate(domain, inPort, outPort) {
outPort=outPort||80;
// Error messages
constdomainInvalidMsg=["\nPlease use a domain name instead of an IP address.","\nDomain is not valid. Please use a valid domain name."];
constportInvalidMsg=["\nPort should be a number.","\nPort should be a number from 1 and 65535."];
constdomainInvalidMsg=[
EOL+"Please use a domain name instead of an IP address.",
EOL+"Domain is not valid. Please use a valid domain name."
];
constportInvalidMsg=[
EOL+"Port should be a number.",
EOL+"Port should be a number from 1 and 65535."
];
// 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.
// 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.
constvalidInPort=parseToInt(inPort);
constvalidOutPort=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.
// 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.
letisValid=true;
// Throw if IP is given instead of domain name.
@ -34,31 +48,41 @@ function validate(domain, inPort, outPort) {
returnisValid=false;
}
// Enter if `inPort` is not defined. This happens for `up static` where no inbound ports are required.
// 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]);// `outPort` is not an integer.
returnisValid=false;
}
if(!(validOutPort>0&&validOutPort<=65535)){
console.log(portInvalidMsg[1]);// `outPort` is not within port range.
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.
// 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]);// Either `inPort` or `outPort` is not an integer.
console.log(portInvalidMsg[0]);
// Either `inPort` or `outPort` is not an integer.