diff --git a/actions/createNewServer.js b/actions/createNewServer.js index 602990b..192d705 100644 --- a/actions/createNewServer.js +++ b/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)); diff --git a/actions/createProxyServer.js b/actions/createProxyServer.js index 6ad3cd6..53f8e16 100644 --- a/actions/createProxyServer.js +++ b/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()); diff --git a/actions/killALL.js b/actions/killALL.js index dfe44ba..c7f1258 100644 --- a/actions/killALL.js +++ b/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; diff --git a/actions/killAllConfirm.js b/actions/killAllConfirm.js index 508e816..5f5fb89 100644 --- a/actions/killAllConfirm.js +++ b/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 { diff --git a/actions/listServers.js b/actions/listServers.js index a5e217c..517fc9b 100644 --- a/actions/listServers.js +++ b/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; diff --git a/utils/listFile.js b/utils/listFile.js index 99faa7b..4b26db7 100644 --- a/utils/listFile.js +++ b/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; } diff --git a/utils/nginxConf.js b/utils/nginxConf.js index 750f02a..b7cf891 100644 --- a/utils/nginxConf.js +++ b/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; diff --git a/utils/requirements.js b/utils/requirements.js index 2c17684..8b6d7fa 100644 --- a/utils/requirements.js +++ b/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 `"); + shell.echo(`\`up\` requires root privileges to work.\ + Please use \`sudo up \``); 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); } }