Browse Source

converted strings to template literals

pull/15/head
Prabhanjan 6 years ago
parent
commit
014ed1dc62
  1. 23
      actions/createNewServer.js
  2. 30
      actions/createProxyServer.js
  3. 10
      actions/killALL.js
  4. 6
      actions/killAllConfirm.js
  5. 4
      actions/listServers.js
  6. 8
      utils/listFile.js
  7. 7
      utils/nginxConf.js
  8. 15
      utils/requirements.js

23
actions/createNewServer.js

@ -8,6 +8,7 @@ const conf = require('../utils/nginxConf');
const nginxReload = require('../utils/nginxReload');
const { appendToList } = require('../utils/listFile');
// Are EOL's neccessary since template literals handle new lines? PS: Unused import
const { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
function createStaticServer(domain, path, outPort) {
@ -18,17 +19,17 @@ function createStaticServer(domain, path, outPort) {
fs.outputFileSync((conf(npath.enabledSites(), domain, outPort)),
// Gets nginx's paths from nginxPath.js
"server {" + EOL +
" listen " + outPort + ";" + EOL +
" listen [::]:" + outPort + ";" + EOL +
" root " + npath.webRoot() + domain + "." + outPort + ";" + EOL +
" index index.html index.htm;" + EOL +
"" + EOL +
" server_name " + domain + ";" + EOL +
" location / {" + EOL +
" try_files $uri $uri/ =404;" + EOL +
" }" + EOL +
"}"
`server {
listen ${outPort};
listen [::]:" ${outPort};
root ${npath.webRoot()}${domain}.${outPort};
index index.html index.htm;
server_name ${domain};
location / {
try_files $uri $uri/ =404;
}
}`
);
shell.rm('-rf', npath.webRootDomain(domain, outPort));

30
actions/createProxyServer.js

@ -17,21 +17,21 @@ function createProxyServer(domain, inPort, outPort) {
// Creates directories if doesn't exist
fs.outputFileSync((conf(npath.enabledSites(), 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 +
"}"
`server {
listen ${outPort};
listen [::]:${outPort};
index index.html index.htm;
server_name ${domain};
location / {
proxy_pass http://localhost:${inPort};
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}`
);
shell.mkdir('-p', npath.enabledSites());

10
actions/killALL.js

@ -21,15 +21,13 @@ function killALL () {
conf(npath.enabledSites()));
// Create the default.conf file
nginxReload();
console.log(EOL + "All servers were killed and reverted to default." +
EOL + "A backup of your old servers.up is " +
"saved in /etc/up-serve/servers.bak.up." +
"Check this if you need to." + EOL
);
console.log(`\nAll servers were killed and reverted to default.
A backup of your old servers.up is saved in /etc/up-serve/servers.bak.up.\
Check this if you need to.`);
}
function noKill () {
return(EOL + "kill-all was interrupted by user.");
return(`\nkill-all was interrupted by user.`);
}
module.exports.kill = killALL;

6
actions/killAllConfirm.js

@ -8,9 +8,9 @@ const killALL = require('./killALL').kill;
const { noKill } = require('./killALL');
function killAllConfirm() {
console.log(EOL + "This action will destroy all nginx servers and return "
+ "to default configuration." + EOL);
if (readlineSync.keyInYN("Are you sure you want to do this?")) {
console.log(`This action will destroy all nginx servers and return\
to default configuration.`);
if (readlineSync.keyInYN(`Are you sure you want to do this?`)) {
killALL();
}
else {

4
actions/listServers.js

@ -7,8 +7,8 @@ const { EOL } = require('os');
function listServers() {
const serversList = readServers();
if(serversList) return(EOL + prettyjson.render(serversList));
else throw new Error("No servers were found! Create some using `up`!");
if(serversList) return(`${prettyjson.render(serversList)}`);
else throw new Error(`No servers were found! Create some using \`up\`!`);
}
module.exports = listServers;

8
utils/listFile.js

@ -45,9 +45,9 @@ function removeFromList (domain, outPort) {
return;
}
}
throw new Error("This domain does not exist in servers.up");
throw new Error(`This domain does not exist in servers.up`);
}
else throw new Error("No servers were created using `up` yet.");
else throw new Error(`No servers were created using \`up\` yet.`);
}
function readServers () {
@ -55,11 +55,11 @@ function readServers () {
if (fs.existsSync(listFilePath())) {
serversList = JSON.parse(fs.readFileSync(listFilePath()));
if(!serversList.domains[0]) {
throw new Error("No domains exist in servers.up");
throw new Error(`No domains exist in servers.up`);
}
}
else {
throw new Error("No servers were created using `up` yet.");
throw new Error(`No servers were created using \`up\` yet.`);
}
return serversList;
}

7
utils/nginxConf.js

@ -3,11 +3,6 @@
// Simple function that takes a path and domain name,
// concatenates them with ".conf" and returns it.
function conf(path, domain, outPort) {
domain = domain || "default";
outPort = outPort || "";
if (outPort != "") outPort = "." + outPort;
return (path + domain + outPort + ".conf");
}
const conf = (path, domain, outPort) => path + (domain || "default") + (outPort ? "." + outPort : "") + ".conf";
module.exports = conf;

15
utils/requirements.js

@ -14,26 +14,23 @@ function requirements() {
// This should be changed to throw if not Debian based distro.
// Eventually, we can add more exceptions as `up` handles more cases.
if(!isLin) {
shell.echo(EOL +
"This is not a Linux or freeBSD distribution. " +
"This tool not written for this distro. " +
"Please raise an issue at " +
chalk.cyan("https://github.com/codefeathers/up-serve") +
" if you want `up` to be ported for your distro");
shell.echo(`\nThis is not a Linux or freeBSD distribution. This tool not written for this distro.
Please raise an issue at ${chalk.cyan("https://github.com/codefeathers/up-serve")}\
if you want \`up\` to be ported for your distro`);
shell.exit(1);
}
// Check if sudo
if (process.getuid() != 0) {
shell.echo("`up` requires root privileges to work."
+ "Please use `sudo up <command>`");
shell.echo(`\`up\` requires root privileges to work.\
Please use \`sudo up <command>\``);
shell.exit(1);
}
// Throw if Nginx is not found
if (!shell.which('nginx')) {
shell.echo(
'I need nginx to work. Install nginx first. https://nginx.org/');
`I need nginx to work. Install nginx first. ${chalk.cyan("https://nginx.org/")}`);
shell.exit(1);
}
}

Loading…
Cancel
Save