A cli tool to quickly create and manage nginx server blocks.
https://up.js.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.7 KiB
39 lines
1.7 KiB
var fs = require('fs-extra');
|
|
var shell = require('shelljs');
|
|
var path = require('path');
|
|
|
|
var npath = require('../utils/nginxPath');
|
|
var conf = require('../utils/nginxConf');
|
|
var nginxReload = require('../utils/nginxReload');
|
|
var appendToList = require('../utils/listFile').appendToList;
|
|
|
|
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.confD(), 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.confD(), 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
|
|
|
|
appendToList(domain, outPort);
|
|
nginxReload();
|
|
}
|
|
|
|
module.exports = createStaticServer;
|