Muthu Kumar
7 years ago
8 changed files with 106 additions and 56 deletions
@ -1,23 +1,29 @@ |
|||
var fs = require('fs-extra') |
|||
var shell = require('shelljs') |
|||
var npath = require('../util/nginxPath') |
|||
var conf = require('../util/nginxConf') |
|||
|
|||
function createProxyServer(domain, inPort) { |
|||
fs.outputFileSync("/test.txt", |
|||
"server {" + "\n" + |
|||
" listen " + outPort + ";" + "\n" + |
|||
" listen [::]:" + outPort + ";" + "\n" + |
|||
" root /var/www/" + domain + ";" + "\n" + |
|||
" index index.html index.htm;" + "\n" + |
|||
"" + "\n" + |
|||
" server_name " + domain + "\n" + |
|||
" location / {" + "\n" + |
|||
" proxy_pass http://localhost:" + inPort + ";" + "\n" + |
|||
" proxy_http_version 1.1;" + "\n" + |
|||
" proxy_set_header Upgrade $http_upgrade;" + "\n" + |
|||
" proxy_set_header Connection 'upgrade';" + "\n" + |
|||
" proxy_set_header Host $host;" + "\n" + |
|||
" proxy_cache_bypass $http_upgrade;" + "\n" + |
|||
function createProxyServer(domain, inPort, outPort) { |
|||
fs.outputFileSync((conf(npath.availableSites(), domain)), |
|||
"server {" + "\r\n" + |
|||
" listen " + outPort + ";" + "\r\n" + |
|||
" listen [::]:" + outPort + ";" + "\r\n" + |
|||
" root /var/www/" + domain + ";" + "\r\n" + |
|||
" index index.html index.htm;" + "\r\n" + |
|||
"" + "\r\n" + |
|||
" server_name " + domain + ";" + "\r\n" + |
|||
" location / {" + "\r\n" + |
|||
" proxy_pass http://localhost:" + inPort + ";" + "\r\n" + |
|||
" proxy_http_version 1.1;" + "\r\n" + |
|||
" proxy_set_header Upgrade $http_upgrade;" + "\r\n" + |
|||
" proxy_set_header Connection 'upgrade';" + "\r\n" + |
|||
" proxy_set_header Host $host;" + "\r\n" + |
|||
" proxy_cache_bypass $http_upgrade;" + "\r\n" + |
|||
" }" + "\r\n" + |
|||
"}" |
|||
) |
|||
) |
|||
shell.mkdir('-p', npath.enabledSites()) |
|||
shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)) |
|||
} |
|||
|
|||
module.exports = createProxyServer |
@ -0,0 +1,5 @@ |
|||
function conf(path, domain) { |
|||
return (path + domain + ".conf") |
|||
} |
|||
|
|||
module.exports = conf |
@ -0,0 +1,17 @@ |
|||
function availableSites() { |
|||
var availableSites = "/etc/nginx/available-sites/" |
|||
return availableSites |
|||
} |
|||
|
|||
function enabledSites() { |
|||
var enabledSites = "/etc/nginx/enabled-sites/" |
|||
return enabledSites |
|||
} |
|||
|
|||
function conf(path, domain) { |
|||
return (path + domain + ".conf") |
|||
} |
|||
|
|||
module.exports.conf = conf |
|||
module.exports.availableSites = availableSites |
|||
module.exports.enabledSites = enabledSites |
@ -0,0 +1,39 @@ |
|||
|
|||
var validator = require('validator') |
|||
// Using Validator
|
|||
var isDomain = validator.isFQDN |
|||
|
|||
function validate(domain, inPort, outPort = undefined) { |
|||
var domainInvalidMsg = "\nDomain is not valid. Please use a valid domain name." |
|||
var portInvalidMsg = ["\nPort should be a number.", "\nPort should be a number from 1 and 65535."] |
|||
var validInPort = /^\d+$/.test(inPort) |
|||
var validOutPort = /^\d+$/.test(outPort) |
|||
var isTrue |
|||
if (!isDomain(domain)) { |
|||
console.log(domainInvalidMsg) |
|||
return isTrue = false |
|||
} |
|||
if (typeof outPort == undefined) { |
|||
if (!validInPort) { |
|||
console.log(portInvalidMsg[0]) |
|||
return isTrue = false |
|||
} |
|||
if (!(validInPort > 0 && validInPort <= 65535)) { |
|||
console.log(portInvalidMsg[1]) |
|||
return isTrue = false |
|||
} |
|||
} |
|||
if (typeof outPort !== undefined) { |
|||
if (!validInPort || !validOutPort) { |
|||
console.log(portInvalidMsg[0]) |
|||
return isTrue = false |
|||
} |
|||
if (!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { |
|||
console.log(portInvalidMsg[1]) |
|||
return isTrue = false |
|||
} |
|||
} |
|||
return isTrue |
|||
} |
|||
|
|||
module.exports = validate |
Loading…
Reference in new issue