Muthu Kumar
7 years ago
6 changed files with 93 additions and 84 deletions
@ -1,35 +1,36 @@ |
|||||
var fs = require('fs-extra'); |
var fs = require('fs-extra'); |
||||
var shell = require('shelljs'); |
var shell = require('shelljs'); |
||||
|
var path = require('path'); |
||||
|
|
||||
var npath = require('../util/nginxPath'); |
var npath = require('../util/nginxPath'); |
||||
var conf = require('../util/nginxConf'); |
var conf = require('../util/nginxConf'); |
||||
var path = require('path'); |
|
||||
var nginxReload = require('../util/nginxReload'); |
var nginxReload = require('../util/nginxReload'); |
||||
|
|
||||
var currentPath = path.normalize(process.cwd()); |
var currentPath = path.normalize(process.cwd()); |
||||
var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
|
var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
|
||||
|
|
||||
function createStaticServer(domain, outPort = 80) { |
function createStaticServer(domain, outPort = 80) { |
||||
fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js
|
fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js
|
||||
"server {" + EOL + |
"server {" + EOL + |
||||
" listen " + outPort + ";" + EOL + |
" listen " + outPort + ";" + EOL + |
||||
" listen [::]:" + outPort + ";" + EOL + |
" listen [::]:" + outPort + ";" + EOL + |
||||
" root " + npath.webRoot() + domain + ";" + EOL + |
" root " + npath.webRoot() + domain + ";" + EOL + |
||||
" index index.html index.htm;" + EOL + |
" index index.html index.htm;" + EOL + |
||||
"" + EOL + |
"" + EOL + |
||||
" server_name " + domain + ";" + EOL + |
" server_name " + domain + ";" + EOL + |
||||
" location / {" + EOL + |
" location / {" + EOL + |
||||
" 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)); // Removes domain from sites-enabled if exists
|
shell.rm('-rf', conf(npath.enabledSites(), domain)); // Removes domain from sites-enabled if exists
|
||||
shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)); // Symlink the conf file from sites-available to sites-enabled
|
shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)); // Symlink the conf file from sites-available to sites-enabled
|
||||
shell.rm('-rf', npath.webRoot() + domain); // Removes domain from webroot if exists
|
shell.rm('-rf', npath.webRoot() + domain); // 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.webRoot() + domain); // Symlink current directory to nginx's web root
|
shell.ln('-sf', currentPath, npath.webRoot() + domain); // Symlink current directory to nginx's web root
|
||||
|
|
||||
nginxReload(); |
nginxReload(); |
||||
}; |
}; |
||||
|
|
||||
module.exports = createStaticServer; |
module.exports = createStaticServer; |
@ -0,0 +1,15 @@ |
|||||
|
var shell = require('shelljs'); |
||||
|
|
||||
|
var npath = require('../util/nginxPath'); |
||||
|
var conf = require('../util/nginxConf'); |
||||
|
var nginxReload = require('../util/nginxReload'); |
||||
|
|
||||
|
function killServer(domain) { |
||||
|
shell.rm('-rf', conf(npath.enabledSites(), domain)); |
||||
|
shell.rm('-rf', conf(npath.availableSites(), domain)); |
||||
|
shell.rm('-rf', npath.webRoot() + domain); |
||||
|
|
||||
|
nginxReload(); |
||||
|
} |
||||
|
|
||||
|
module.exports = killServer; |
@ -1,36 +1,36 @@ |
|||||
{ |
{ |
||||
"name": "up-serve", |
"name": "up-serve", |
||||
"version": "0.1.3", |
"version": "0.1.4", |
||||
"description": "A cli tool to quickly create and manage nginx server blocks.", |
"description": "A cli tool to quickly create and manage nginx server blocks.", |
||||
"main": "index.js", |
"main": "index.js", |
||||
"scripts": { |
"scripts": { |
||||
"test": "echo \"Error: no test specified\" && exit 1" |
"test": "echo \"Error: no test specified\" && exit 1" |
||||
}, |
}, |
||||
"repository": { |
"repository": { |
||||
"type": "git", |
"type": "git", |
||||
"url": "git+https://github.com/codefeathers/up-serve.git" |
"url": "git+https://github.com/codefeathers/up-serve.git" |
||||
}, |
}, |
||||
"keywords": [ |
"keywords": [ |
||||
"up", |
"up", |
||||
"serve", |
"serve", |
||||
"nginx", |
"nginx", |
||||
"server", |
"server", |
||||
"block" |
"block" |
||||
], |
], |
||||
"bin": { |
"bin": { |
||||
"up": "./index.js" |
"up": "./index.js" |
||||
}, |
}, |
||||
"author": "Muthu Kumar (@MKRhere)", |
"author": "Muthu Kumar (@MKRhere)", |
||||
"license": "MIT", |
"license": "MIT", |
||||
"bugs": { |
"bugs": { |
||||
"url": "https://github.com/codefeathers/up-serve/issues" |
"url": "https://github.com/codefeathers/up-serve/issues" |
||||
}, |
}, |
||||
"homepage": "https://github.com/codefeathers/up-serve#readme", |
"homepage": "https://github.com/codefeathers/up-serve#readme", |
||||
"dependencies": { |
"dependencies": { |
||||
"chalk": "^2.3.0", |
"chalk": "^2.3.0", |
||||
"commander": "^2.11.0", |
"commander": "^2.11.0", |
||||
"fs-extra": "^4.0.2", |
"fs-extra": "^4.0.2", |
||||
"shelljs": "^0.7.8", |
"shelljs": "^0.7.8", |
||||
"validator": "^9.1.1" |
"validator": "^9.1.1" |
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue