Browse Source

Merge pull request #8 from codefeathers/develop

v0.2.1 Bug fixes, patch for `up kill-all`
pull/14/head
Muthu Kumar 7 years ago
committed by GitHub
parent
commit
85100fc244
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 11
      Roadmap.md
  3. 2
      actions/createProxyServer.js
  4. 11
      actions/killALL.js
  5. 7
      actions/killAllConfirm.js
  6. 84
      build/defaultNginx.conf
  7. 22
      index.js
  8. 2
      package-lock.json
  9. 2
      package.json
  10. 9
      utils/listFile.js
  11. 5
      utils/nginxConf.js
  12. 2
      utils/nginxReload.js

2
README.md

@ -8,7 +8,7 @@
# up
> Current version: `up v.0.2.0 (Alpha)`
> Current version: `up v.0.2.1 (Alpha)`
> Notes: `up` is now in Alpha! 🎉 [(Changelog)](Changelog.md)\
> ⚠️ ❌ `up` is pretty useable so far. If you're testing `up` on a development server, do give us feedback.

11
Roadmap.md

@ -8,12 +8,12 @@ This living document details our plans for `up`. If you would like to request fe
## The Roadmap
- [ ] MVP - Minimum Viable Product.
- [x] MVP - Minimum Viable Product.
- [x] `up static` and `up proxy` MUST work.
- [ ] `up kill` MUST work.
- [ ]List servers option.
- [ ] `up list` MUST provide list of servers running by parsing nginx's `sites-available` and `sites-enabled` folders.
- [ ] `up static` MUST have an option to specify path to root. Example: `up static example.com ./public`.
- [x] `up kill` MUST work.
- [x]List servers option.
- [x] `up list` MUST provide list of servers running from `/etc/up-serve/servers.up` file.
- [x] `up static` MUST have an option to specify path to root. Example: `up static example.com ./public`.
- [ ] `up static` and `up proxy` MAY take a Git URL to deploy. Example:
1. `up static example.com --git https://github.com/h5bp/html5-boilerplate /html`
2. `up proxy example.com 5000 --git https://github.com/heroku/node-js-sample`
@ -21,7 +21,6 @@ This living document details our plans for `up`. If you would like to request fe
- [ ] MUST add a `-s` or `--secure` flag to enable automatic HTTPS config with HTTP/2 enabled by default.
- [ ] HSTS MAY be enabled with a `-s -h`, `-sh`, `-secure -hsts` or `--secure-hsts` flag. Will warn user to be sure of what they are doing.
- [ ] MAY add a `-c` flag to use `certbot` to automatically generate certificates using letsencrypt.
- [ ] SHOULD work on a way to make `up` work on distros other than Deb/Ubuntu based.
- [ ] MAY make `up` work on Windows.
Want more features or prioritize something? Raise an [issue!](https://github.com/codefeathers/up-serve/issues)

2
actions/createProxyServer.js

@ -31,7 +31,7 @@ function createProxyServer(domain, inPort, outPort) {
" }" + EOL +
"}"
);
shell.mkdir('-p', npath.confD());
shell.mkdir('-p', npath.enabledSites());
// Creates directories if doesn't exist
shell.ln('-sf', conf(npath.confD(), domain, outPort),

11
actions/killALL.js

@ -1,11 +1,13 @@
'use strict';
const shell = require('shelljs');
const path = require('path');
const { EOL } = require('os');
const npath = require('../utils/nginxPath');
const conf = require('../utils/nginxConf');
const nginxReload = require('../utils/nginxReload');
function killALL () {
shell.rm('-Rf', npath.serversBakUp);
@ -17,21 +19,20 @@ function killALL () {
shell.mkdir('-p', npath.confD());
shell.mkdir('-p', npath.enabledSites());
shell.mkdir('-p', npath.webRoot());
shell.cp('./build/defaultNginx.conf', conf(npath.confD()));
shell.cp((path.join(__dirname, '/../build/defaultNginx.conf')),
conf(npath.enabledSites()));
// Create the default.conf file
shell.ln('-sf', npath.confD() + "default.conf",
npath.enabledSites() + "default.conf");
// Symlink the default.conf file from confD to sites-enabled
console.log("All servers were killed and reverted to default.");
console.log(EOL + [
"A backup of your old servers.up is " +
"saved in /etc/up-serve/servers.bak.up.",
"Check this if you need to."
].join(EOL) + EOL);
nginxReload();
}
function noKill () {
console.log("\nkill-all was interrupted by user.");
console.log(EOL + "kill-all was interrupted by user.");
}
module.exports.kill = killALL;

7
actions/killAllConfirm.js

@ -1,12 +1,15 @@
'use strict';
const readlineSync = require('readline-sync');
const { EOL } = require('os');
const killALL = require('./killALL').kill;
const { noKill } = require('./killALL');
function killAllConfirm() {
console.log("\nThis action will destroy all nginx servers and return "
+ "to default configuration.");
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?")) {
killALL();
}

84
build/defaultNginx.conf

@ -1,49 +1,3 @@
#user nobody;
#Defines which Linux system user will own and run the Nginx server
worker_processes 1;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.
#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.
#pid logs/nginx.pid;
#nginx will write its master process ID(PID).
events {
worker_connections 1024;
# worker_processes and worker_connections allows you to calculate maxclients value:
# max_clients = worker_processes * worker_connections
}
http {
include mime.types;
# anything written in /opt/nginx/conf/mime.types is interpreted as if written inside the http { } block
default_type application/octet-stream;
#
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
# If serving locally stored static files, sendfile is essential to speed up the server,
# But if using as reverse proxy one can deactivate it
#tcp_nopush on;
# works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once.
#keepalive_timeout 0;
keepalive_timeout 65;
# timeout during which a keep-alive client connection will stay open.
#gzip on;
# tells the server to use on-the-fly gzip compression.
server {
# You would want to make a separate file with its own server block for each virtual domain
# on your server and then include them.
@ -96,41 +50,3 @@ http {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

22
index.js

@ -7,7 +7,6 @@ const { EOL } = require('os');
// Requiring npm modules
const program = require('commander');
const chalk = require('chalk');
//var fs = require('fs-extra');
// Requiring Actions
const createProxyServer = require('./actions/createProxyServer');
@ -28,7 +27,16 @@ requirements(); // Comment in development and uncomment this line in production.
// This should check whether the OS is compatible with this version of `up`
program
.version('0.2.0');
.version('0.2.1');
let cmdValue;
program
.version('0.1.0')
.arguments('<cmd>')
.action(function (cmd) {
cmdValue = cmd;
});
program
.command('static <domain> [outPort]')
@ -65,8 +73,7 @@ program
"Done! Your reverse proxy server has been set up!",
"Point your domain to this server and check " +
chalk.cyan(domain) +
" to verify!"
].join(EOL));
" to verify!"].join(EOL));
});
program
@ -90,10 +97,10 @@ program
.command('kill-all')
.description('Warning! Will completely kill all servers and reset nginx')
.action(function() {
//new Promise(resolve => killed\killAllConfirm();
killAllConfirm();
});
program
.command('*') // This should pick invalid commands, but it doesn't, yet.
.action(function () {
@ -122,3 +129,8 @@ program.on('--help', function () {
// Parses commands passed to `up` and chooses one of the above commands.
program.parse(process.argv);
if (typeof cmdValue === 'undefined') {
console.log(EOL + "No command was given. `up --help` for help info.");
process.exit(1);
}

2
package-lock.json

@ -1,6 +1,6 @@
{
"name": "up-serve",
"version": "0.1.9",
"version": "0.2.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

2
package.json

@ -1,6 +1,6 @@
{
"name": "up-serve",
"version": "0.2.0",
"version": "0.2.1",
"description": "A cli tool to quickly create and manage nginx server blocks.",
"main": "index.js",
"scripts": {

9
utils/listFile.js

@ -45,9 +45,14 @@ function removeFromList (domain, outPort) {
}
function readServers () {
const serversList = JSON.parse(fs.readFileSync(listFilePath()));
let serversList;
if (fs.existsSync(listFilePath())) {
serversList = JSON.parse(fs.readFileSync(listFilePath()));
if(!serversList.domains[0]) return undefined;
}
else {
return "Servers were not created";
}
return serversList;
}

5
utils/nginxConf.js

@ -4,7 +4,10 @@
// concatenates them with ".conf" and returns it.
function conf(path, domain, outPort) {
return (path + domain + "." + outPort + ".conf");
domain = domain || "default";
outPort = outPort || "";
if (outPort != "") outPort = "." + outPort;
return (path + domain + outPort + ".conf");
}
module.exports = conf;

2
utils/nginxReload.js

@ -8,7 +8,7 @@ function nginxReload() {
console.error("exec error: " + error);
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
return;
process.exit(1);
}
});
}

Loading…
Cancel
Save