Muthu Kumar
7 years ago
8 changed files with 148 additions and 121 deletions
@ -0,0 +1,21 @@ |
|||
{ |
|||
"env": { |
|||
"node": true |
|||
}, |
|||
"extends": "eslint:recommended", |
|||
"rules": { |
|||
"no-console": "off", |
|||
"indent": [ |
|||
"error", |
|||
"tab" |
|||
], |
|||
"linebreak-style": [ |
|||
"error", |
|||
"unix" |
|||
], |
|||
"semi": [ |
|||
"error", |
|||
"always" |
|||
] |
|||
} |
|||
} |
@ -1,34 +1,34 @@ |
|||
var fs = require('fs-extra'); |
|||
var shell = require('shelljs'); |
|||
|
|||
var npath = require('../util/nginxPath'); |
|||
var conf = require('../util/nginxConf'); |
|||
var nginxReload = require('../util/nginxReload'); |
|||
|
|||
var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
|
|||
|
|||
function createProxyServer(domain, inPort, outPort) { |
|||
fs.outputFileSync((conf(npath.availableSites(), domain, outPort)), |
|||
"server {" + EOL + |
|||
" listen " + outPort + ";" + EOL + |
|||
" listen [::]:" + outPort + ";" + EOL + |
|||
" index index.html index.htm;" + EOL + |
|||
"" + EOL + |
|||
" server_name " + domain + ";" + EOL + |
|||
" location / {" + EOL + |
|||
" proxy_pass http://localhost:" + inPort + ";" + EOL + |
|||
" proxy_http_version 1.1;" + EOL + |
|||
" proxy_set_header Upgrade $http_upgrade;" + EOL + |
|||
" proxy_set_header Connection 'upgrade';" + EOL + |
|||
" proxy_set_header Host $host;" + EOL + |
|||
" proxy_cache_bypass $http_upgrade;" + EOL + |
|||
" }" + EOL + |
|||
"}" |
|||
) |
|||
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
|
|||
|
|||
nginxReload(); |
|||
}; |
|||
|
|||
var fs = require('fs-extra'); |
|||
var shell = require('shelljs'); |
|||
|
|||
var npath = require('../util/nginxPath'); |
|||
var conf = require('../util/nginxConf'); |
|||
var nginxReload = require('../util/nginxReload'); |
|||
|
|||
var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows.
|
|||
|
|||
function createProxyServer(domain, inPort, outPort) { |
|||
fs.outputFileSync((conf(npath.availableSites(), domain, outPort)), |
|||
"server {" + EOL + |
|||
" listen " + outPort + ";" + EOL + |
|||
" listen [::]:" + outPort + ";" + EOL + |
|||
" index index.html index.htm;" + EOL + |
|||
"" + EOL + |
|||
" server_name " + domain + ";" + EOL + |
|||
" location / {" + EOL + |
|||
" proxy_pass http://localhost:" + inPort + ";" + EOL + |
|||
" proxy_http_version 1.1;" + EOL + |
|||
" proxy_set_header Upgrade $http_upgrade;" + EOL + |
|||
" proxy_set_header Connection 'upgrade';" + EOL + |
|||
" proxy_set_header Host $host;" + EOL + |
|||
" proxy_cache_bypass $http_upgrade;" + EOL + |
|||
" }" + EOL + |
|||
"}" |
|||
); |
|||
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
|
|||
|
|||
nginxReload(); |
|||
} |
|||
|
|||
module.exports = createProxyServer; |
@ -1,36 +1,37 @@ |
|||
var fs = require('fs-extra'); |
|||
var shell = require('shelljs'); |
|||
var path = require('path'); |
|||
|
|||
var npath = require('../util/nginxPath'); |
|||
var conf = require('../util/nginxConf'); |
|||
var nginxReload = require('../util/nginxReload'); |
|||
|
|||
var currentPath = path.normalize(process.cwd()); |
|||
var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
|
|||
|
|||
function createStaticServer(domain, outPort = 80) { |
|||
fs.outputFileSync((conf(npath.availableSites(), domain, outPort)), // Gets nginx's paths from nginxPath.js
|
|||
"server {" + EOL + |
|||
" listen " + outPort + ";" + EOL + |
|||
" listen [::]:" + outPort + ";" + EOL + |
|||
" root " + npath.webRoot() + domain + ";" + EOL + |
|||
" index index.html index.htm;" + EOL + |
|||
"" + EOL + |
|||
" server_name " + domain + ";" + EOL + |
|||
" location / {" + EOL + |
|||
" try_files $uri $uri/ =404;" + EOL + |
|||
" }" + EOL + |
|||
"}" |
|||
) |
|||
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.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.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
|
|||
|
|||
nginxReload(); |
|||
}; |
|||
|
|||
var fs = require('fs-extra'); |
|||
var shell = require('shelljs'); |
|||
var path = require('path'); |
|||
|
|||
var npath = require('../util/nginxPath'); |
|||
var conf = require('../util/nginxConf'); |
|||
var nginxReload = require('../util/nginxReload'); |
|||
|
|||
var currentPath = path.normalize(process.cwd()); |
|||
var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows.
|
|||
|
|||
function createStaticServer(domain, outPort) { |
|||
outPort = outPort || 80; |
|||
fs.outputFileSync((conf(npath.availableSites(), domain, outPort)), // Gets nginx's paths from nginxPath.js
|
|||
"server {" + EOL + |
|||
" listen " + outPort + ";" + EOL + |
|||
" listen [::]:" + outPort + ";" + EOL + |
|||
" root " + npath.webRoot() + domain + ";" + EOL + |
|||
" index index.html index.htm;" + EOL + |
|||
"" + EOL + |
|||
" server_name " + domain + ";" + EOL + |
|||
" location / {" + EOL + |
|||
" try_files $uri $uri/ =404;" + EOL + |
|||
" }" + EOL + |
|||
"}" |
|||
); |
|||
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.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.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
|
|||
|
|||
nginxReload(); |
|||
} |
|||
|
|||
module.exports = createStaticServer; |
@ -1,27 +1,27 @@ |
|||
// These functions just return paths. Later, these should be modified to poll from nginx's config.
|
|||
|
|||
var available = "/etc/nginx/sites-available/"; |
|||
var enabled = "/etc/nginx/sites-enabled/"; |
|||
var wwwRoot = "/var/www/"; |
|||
|
|||
function availableSites() { |
|||
return available; |
|||
} |
|||
|
|||
function enabledSites() { |
|||
return enabled; |
|||
} |
|||
|
|||
function webRoot() { |
|||
return wwwRoot; |
|||
} |
|||
|
|||
function webRootDomain(domain, outPort) { |
|||
rootWithDomain = wwwRoot + domain + "." + outPort; |
|||
return rootWithDomain; |
|||
} |
|||
|
|||
module.exports.availableSites = availableSites; |
|||
module.exports.enabledSites = enabledSites; |
|||
module.exports.webRoot = webRoot; |
|||
// These functions just return paths. Later, these should be modified to poll from nginx's config.
|
|||
|
|||
var available = "/etc/nginx/sites-available/"; |
|||
var enabled = "/etc/nginx/sites-enabled/"; |
|||
var wwwRoot = "/var/www/"; |
|||
|
|||
function availableSites() { |
|||
return available; |
|||
} |
|||
|
|||
function enabledSites() { |
|||
return enabled; |
|||
} |
|||
|
|||
function webRoot() { |
|||
return wwwRoot; |
|||
} |
|||
|
|||
function webRootDomain(domain, outPort) { |
|||
var rootWithDomain = wwwRoot + domain + "." + outPort; |
|||
return rootWithDomain; |
|||
} |
|||
|
|||
module.exports.availableSites = availableSites; |
|||
module.exports.enabledSites = enabledSites; |
|||
module.exports.webRoot = webRoot; |
|||
module.exports.webRootDomain = webRootDomain; |
@ -1,14 +1,14 @@ |
|||
var { execSync } = require('child_process'); |
|||
var execSync = require('child_process').execSync; |
|||
|
|||
function nginxReload() { |
|||
execSync('service nginx reload', function (error, stdout, stderr) { |
|||
if (error) { |
|||
console.error(`exec error: ${error}`); |
|||
console.log(`stdout: ${stdout}`); |
|||
console.log(`stderr: ${stderr}`); |
|||
execSync('service nginx reload', function (error, stdout, stderr) { |
|||
if (error) { |
|||
console.error("exec error: " + error); |
|||
console.log("stdout: " + stdout); |
|||
console.log("stderr: " + stderr); |
|||
return; |
|||
} |
|||
}) |
|||
} |
|||
}); |
|||
} |
|||
|
|||
module.exports = nginxReload; |
Loading…
Reference in new issue