From 9e2b3dbaa58f3d3d2fd0eae67708bee7546f17c2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 7 Oct 2016 15:28:46 -0600 Subject: [PATCH 1/3] add version flag --- serve.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/serve.js b/serve.js index ad41e7d..bbc71b4 100755 --- a/serve.js +++ b/serve.js @@ -139,6 +139,14 @@ function run() { var letsencryptHost = argv['letsencrypt-certs']; var tls = require('tls'); + if (argv.V || argv.version || argv.v) { + if (argv.v) { + console.warn("flag -v is reserved for future use. Use -V or --version for version information."); + } + console.info('v' + require('./package.json').version); + return; + } + // letsencrypt var httpsOptions = require('localhost.daplie.com-certificates').merge({}); var secureContext; From d192cd8255be2e8e4a361372957e2b101edf3ebe Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 7 Oct 2016 15:28:54 -0600 Subject: [PATCH 2/3] v1.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fadbfe..0d1dcc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serve-https", - "version": "1.6.0", + "version": "1.6.1", "description": "Serves HTTPS using TLS (SSL) certs for localhost.daplie.com - great for testing and development.", "main": "serve.js", "scripts": { From 344a3eba41f7976e58db498e908802e2bb7f39f2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 11 Oct 2016 10:58:18 -0600 Subject: [PATCH 3/3] minor refactoring --- serve.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/serve.js b/serve.js index bbc71b4..aaca97e 100755 --- a/serve.js +++ b/serve.js @@ -26,9 +26,13 @@ function showError(err, port) { } function createInsecureServer(port, pubdir, opts) { - return new PromiseA(function (resolve) { + return new PromiseA(function (realResolve) { var server = http.createServer(); + function resolve() { + realResolve(server); + } + server.on('error', function (err) { if (opts.errorInsecurePort || opts.manualInsecurePort) { showError(err, port); @@ -41,9 +45,7 @@ function createInsecureServer(port, pubdir, opts) { return createInsecureServer(insecurePortFallback, pubdir, opts).then(resolve); }); - server.on('request', require('redirect-https')({ - port: opts.port - })); + server.on('request', opts.redirectApp); server.listen(port, function () { opts.insecurePort = port; @@ -53,15 +55,20 @@ function createInsecureServer(port, pubdir, opts) { } function createServer(port, pubdir, content, opts) { - return new PromiseA(function (resolve) { + return new PromiseA(function (realResolve) { var server = https.createServer(opts.httpsOptions); var app = require('./app'); var directive = { public: pubdir, content: content, livereload: opts.livereload , servername: opts.servername, expressApp: opts.expressApp }; - var redirectApp = require('redirect-https')({ - port: port - }); + var insecureServer; + + function resolve() { + realResolve({ + plainServer: insecureServer + , server: server + }); + } server.on('error', function (err) { if (opts.errorPort || opts.manualPort) { @@ -77,6 +84,7 @@ function createServer(port, pubdir, content, opts) { server.listen(port, function () { opts.port = port; + opts.redirectOptions.port = port; if (opts.livereload) { opts.lrPort = opts.lrPort || lrPort; @@ -93,7 +101,10 @@ function createServer(port, pubdir, content, opts) { } if ('false' !== opts.insecurePort && httpPort !== opts.insecurePort) { - return createInsecureServer(opts.insecurePort, pubdir, opts).then(resolve); + return createInsecureServer(opts.insecurePort, pubdir, opts).then(function (_server) { + insecureServer = _server; + resolve(); + }); } else { opts.insecurePort = opts.port; resolve(); @@ -108,7 +119,7 @@ function createServer(port, pubdir, content, opts) { server.on('request', function (req, res) { if (!req.socket.encrypted) { - redirectApp(req, res); + opts.redirectApp(req, res); return; } @@ -246,6 +257,12 @@ function run() { opts.expressApp = require(path.resolve(process.cwd(), argv['express-app'])); } + // can be changed to tunnel external port + opts.redirectOptions = { + port: opts.port + }; + opts.redirectApp = require('redirect-https')(opts.redirectOptions); + return createServer(port, pubdir, content, opts).then(function () { var msg; var p;