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. 9
      actions/killAllConfirm.js
  6. 158
      build/defaultNginx.conf
  7. 22
      index.js
  8. 2
      package-lock.json
  9. 2
      package.json
  10. 11
      utils/listFile.js
  11. 5
      utils/nginxConf.js
  12. 2
      utils/nginxReload.js

2
README.md

@ -8,7 +8,7 @@
# up # 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)\ > 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. > ⚠️ ❌ `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 ## The Roadmap
- [ ] MVP - Minimum Viable Product. - [x] MVP - Minimum Viable Product.
- [x] `up static` and `up proxy` MUST work. - [x] `up static` and `up proxy` MUST work.
- [ ] `up kill` MUST work. - [x] `up kill` MUST work.
- [ ]List servers option. - [x]List servers option.
- [ ] `up list` MUST provide list of servers running by parsing nginx's `sites-available` and `sites-enabled` folders. - [x] `up list` MUST provide list of servers running from `/etc/up-serve/servers.up` file.
- [ ] `up static` MUST have an option to specify path to root. Example: `up static example.com ./public`. - [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: - [ ] `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` 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` 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. - [ ] 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. - [ ] 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. - [ ] 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. - [ ] MAY make `up` work on Windows.
Want more features or prioritize something? Raise an [issue!](https://github.com/codefeathers/up-serve/issues) 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 + " }" + EOL +
"}" "}"
); );
shell.mkdir('-p', npath.confD());
shell.mkdir('-p', npath.enabledSites()); shell.mkdir('-p', npath.enabledSites());
// Creates directories if doesn't exist // Creates directories if doesn't exist
shell.ln('-sf', conf(npath.confD(), domain, outPort), shell.ln('-sf', conf(npath.confD(), domain, outPort),

11
actions/killALL.js

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

9
actions/killAllConfirm.js

@ -1,12 +1,15 @@
'use strict'; 'use strict';
const readlineSync = require('readline-sync'); const readlineSync = require('readline-sync');
const { EOL } = require('os');
const killALL = require('./killALL').kill; const killALL = require('./killALL').kill;
const { noKill } = require('./killALL'); const { noKill } = require('./killALL');
function killAllConfirm() { function killAllConfirm() {
console.log("\nThis action will destroy all nginx servers and return " console.log(EOL + "This action will destroy all nginx servers and return "
+ "to default configuration."); + "to default configuration." + EOL);
if (readlineSync.keyInYN("Are you sure you want to do this?")) { if (readlineSync.keyInYN("Are you sure you want to do this?")) {
killALL(); killALL();
} }
@ -15,4 +18,4 @@ function killAllConfirm() {
} }
} }
module.exports = killAllConfirm; module.exports = killAllConfirm;

158
build/defaultNginx.conf

@ -1,136 +1,52 @@
#user nobody; server {
#Defines which Linux system user will own and run the Nginx 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.
worker_processes 1; listen 80;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores. #tells Nginx the hostname and the TCP port where it should listen for HTTP connections.
# listen 80; is equivalent to listen *:80;
#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; server_name localhost;
# works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once. # lets you doname-based virtual hosting
#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.
listen 80;
#tells Nginx the hostname and the TCP port where it should listen for HTTP connections.
# listen 80; is equivalent to listen *:80;
server_name localhost;
# lets you doname-based virtual hosting
#charset koi8-r; #charset koi8-r;
#access_log logs/host.access.log main; #access_log logs/host.access.log main;
location / { location / {
#The location setting lets you configure how nginx responds to requests for resources within the server. #The location setting lets you configure how nginx responds to requests for resources within the server.
root html; root html;
index index.html index.htm; index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} }
#error_page 404 /404.html;
# another virtual host using mix of IP-, name-, and port-based configuration # redirect server error pages to the static page /50x.html
# #
#server { error_page 500 502 503 504 /50x.html;
# listen 8000; location = /50x.html {
# listen somename:8080; root html;
# server_name somename alias another.alias; }
# location / { # proxy the PHP scripts to Apache listening on 127.0.0.1:80
# root html; #
# index index.html index.htm; #location ~ \.php$ {
# } # proxy_pass http://127.0.0.1;
#} #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# HTTPS server
# #
#server { #location ~ \.php$ {
# listen 443 ssl; # root html;
# server_name localhost; # fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# ssl_certificate cert.pem; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# ssl_certificate_key cert.key; # include fastcgi_params;
# 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;
# }
#} #}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} }

22
index.js

@ -7,7 +7,6 @@ const { EOL } = require('os');
// Requiring npm modules // Requiring npm modules
const program = require('commander'); const program = require('commander');
const chalk = require('chalk'); const chalk = require('chalk');
//var fs = require('fs-extra');
// Requiring Actions // Requiring Actions
const createProxyServer = require('./actions/createProxyServer'); 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` // This should check whether the OS is compatible with this version of `up`
program program
.version('0.2.0'); .version('0.2.1');
let cmdValue;
program
.version('0.1.0')
.arguments('<cmd>')
.action(function (cmd) {
cmdValue = cmd;
});
program program
.command('static <domain> [outPort]') .command('static <domain> [outPort]')
@ -65,8 +73,7 @@ program
"Done! Your reverse proxy server has been set up!", "Done! Your reverse proxy server has been set up!",
"Point your domain to this server and check " + "Point your domain to this server and check " +
chalk.cyan(domain) + chalk.cyan(domain) +
" to verify!" " to verify!"].join(EOL));
].join(EOL));
}); });
program program
@ -90,10 +97,10 @@ program
.command('kill-all') .command('kill-all')
.description('Warning! Will completely kill all servers and reset nginx') .description('Warning! Will completely kill all servers and reset nginx')
.action(function() { .action(function() {
//new Promise(resolve => killed\killAllConfirm();
killAllConfirm(); killAllConfirm();
}); });
program program
.command('*') // This should pick invalid commands, but it doesn't, yet. .command('*') // This should pick invalid commands, but it doesn't, yet.
.action(function () { .action(function () {
@ -122,3 +129,8 @@ program.on('--help', function () {
// Parses commands passed to `up` and chooses one of the above commands. // Parses commands passed to `up` and chooses one of the above commands.
program.parse(process.argv); 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", "name": "up-serve",
"version": "0.1.9", "version": "0.2.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

2
package.json

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

11
utils/listFile.js

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

5
utils/nginxConf.js

@ -4,7 +4,10 @@
// concatenates them with ".conf" and returns it. // concatenates them with ".conf" and returns it.
function conf(path, domain, outPort) { 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; module.exports = conf;

2
utils/nginxReload.js

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

Loading…
Cancel
Save