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.
46 lines
1.4 KiB
46 lines
1.4 KiB
7 years ago
|
'use strict';
|
||
7 years ago
|
|
||
7 years ago
|
const fs = require('fs-extra');
|
||
|
const shell = require('shelljs');
|
||
7 years ago
|
|
||
7 years ago
|
const npath = require('../utils/nginxPath');
|
||
|
const conf = require('../utils/nginxConf');
|
||
|
const nginxReload = require('../utils/nginxReload');
|
||
|
const { appendToList } = require('../utils/listFile');
|
||
|
|
||
|
const { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
|
||
7 years ago
|
|
||
7 years ago
|
function createStaticServer(domain, path, outPort) {
|
||
7 years ago
|
outPort = outPort || 80;
|
||
7 years ago
|
|
||
|
shell.mkdir('-p', npath.enabledSites());
|
||
|
// Creates directories if doesn't exist
|
||
7 years ago
|
|
||
7 years ago
|
fs.outputFileSync((conf(npath.enabledSites(), domain, outPort)),
|
||
7 years ago
|
// Gets nginx's paths from nginxPath.js
|
||
7 years ago
|
"server {" + EOL +
|
||
|
" listen " + outPort + ";" + EOL +
|
||
|
" listen [::]:" + outPort + ";" + EOL +
|
||
7 years ago
|
" root " + npath.webRoot() + domain + "." + outPort + ";" + EOL +
|
||
7 years ago
|
" index index.html index.htm;" + EOL +
|
||
|
"" + EOL +
|
||
|
" server_name " + domain + ";" + EOL +
|
||
|
" location / {" + EOL +
|
||
|
" try_files $uri $uri/ =404;" + EOL +
|
||
|
" }" + EOL +
|
||
|
"}"
|
||
|
);
|
||
7 years ago
|
|
||
7 years ago
|
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
|
||
7 years ago
|
shell.ln('-sf', path, npath.webRootDomain(domain, outPort));
|
||
7 years ago
|
// Symlink current directory to nginx's web root
|
||
7 years ago
|
|
||
7 years ago
|
appendToList(domain, outPort);
|
||
7 years ago
|
nginxReload();
|
||
|
}
|
||
|
|
||
7 years ago
|
module.exports = createStaticServer;
|