@ -24,11 +24,11 @@ function createProxyServer(domain, inPort, outPort) {
" proxy_cache_bypass $http_upgrade;"+EOL+
" proxy_cache_bypass $http_upgrade;"+EOL+
" }"+EOL+
" }"+EOL+
"}"
"}"
)
);
shell.mkdir('-p',npath.enabledSites());// Creates directory if doesn't exist
shell.mkdir('-p',npath.enabledSites());// Creates directory if doesn't exist
shell.ln('-sf',conf(npath.availableSites(),domain,outPort),conf(npath.enabledSites(),domain,outPort));// Symlink the conf file from sites-available to sites-enabled
shell.ln('-sf',conf(npath.availableSites(),domain,outPort),conf(npath.enabledSites(),domain,outPort));// Symlink the conf file from sites-available to sites-enabled
@ -7,9 +7,10 @@ var conf = require('../util/nginxConf');
varnginxReload=require('../util/nginxReload');
varnginxReload=require('../util/nginxReload');
varcurrentPath=path.normalize(process.cwd());
varcurrentPath=path.normalize(process.cwd());
var{EOL}=require('os');// \n if used on Linux, \r\n if used on Windows.
varEOL=require('os').EOL;// \n if used on Linux, \r\n if used on Windows.
functioncreateStaticServer(domain,outPort=80){
functioncreateStaticServer(domain,outPort){
outPort=outPort||80;
fs.outputFileSync((conf(npath.availableSites(),domain,outPort)),// Gets nginx's paths from nginxPath.js
fs.outputFileSync((conf(npath.availableSites(),domain,outPort)),// Gets nginx's paths from nginxPath.js
"server {"+EOL+
"server {"+EOL+
" listen "+outPort+";"+EOL+
" listen "+outPort+";"+EOL+
@ -22,15 +23,15 @@ function createStaticServer(domain, outPort = 80) {
" try_files $uri $uri/ =404;"+EOL+
" try_files $uri $uri/ =404;"+EOL+
" }"+EOL+
" }"+EOL+
"}"
"}"
)
);
shell.mkdir('-p',npath.enabledSites());// Creates directory if doesn't exist
shell.mkdir('-p',npath.enabledSites());// Creates directory if doesn't exist
shell.rm('-rf',conf(npath.enabledSites(),domain,outPort));// Removes domain from sites-enabled if exists
shell.rm('-rf',conf(npath.enabledSites(),domain,outPort));// Removes domain from sites-enabled if exists
shell.ln('-sf',conf(npath.availableSites(),domain,outPort),conf(npath.enabledSites(),domain,outPort));// Symlink the conf file from sites-available to sites-enabled
shell.ln('-sf',conf(npath.availableSites(),domain,outPort),conf(npath.enabledSites(),domain,outPort));// Symlink the conf file from sites-available to sites-enabled
shell.rm('-rf',npath.webRootDomain(domain,outPort));// Removes domain from webroot if exists
shell.rm('-rf',npath.webRootDomain(domain,outPort));// Removes domain from webroot if exists
shell.mkdir('-p',npath.webRoot());// Creating the nginx www path if it doesn't exist so symlink doesn't fail
shell.mkdir('-p',npath.webRoot());// Creating the nginx www path if it doesn't exist so symlink doesn't fail
shell.ln('-sf',currentPath,npath.webRootDomain(domain,outPort));// Symlink current directory to nginx's web root
shell.ln('-sf',currentPath,npath.webRootDomain(domain,outPort));// Symlink current directory to nginx's web root
.description('Create a static server at this folder.')
.description('Create a static server at this folder.')
.action(function(domain,outPort=80){//If outport is not given, 80 is set as default. Later, change this default to reflect nginx's settings.
.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.
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!");
@ -33,7 +32,8 @@ program
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"){//Inbound port is necessary, but outbound is set to 80 by default. Again, will change this to reflect nginx's settings.
.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.
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!");
@ -49,7 +49,8 @@ program
program
program
.command('kill <domain> [ourPort]')
.command('kill <domain> [ourPort]')
.description('Kill a server.')
.description('Kill a server.')
.action(function(domain,outPort=80){
.action(function(domain,outPort){
outPort=outPort||"80";// This is a string because regex needs to validate it.
killServer(domain,outPort);
killServer(domain,outPort);
console.log("\nDone! Your server has been killed!\n");
console.log("\nDone! Your server has been killed!\n");
});
});
@ -57,7 +58,7 @@ program
program
program
.command('*')// This should pick invalid commands, but it doesn't, yet.
.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.
// Adds custom help text to the automatically generated help.