From ae73e16ac268bafb6ec1933d9df807c12d8fb803 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Thu, 21 Nov 2013 21:16:59 -0500 Subject: [PATCH] add --secure flag to indicate proxy can support https requests When --secure is set, all urls will be sent back with https so use will use secure proxy. --- bin/server | 7 ++++++- server.js | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/server b/bin/server index 6e8fc81..e53ee57 100755 --- a/bin/server +++ b/bin/server @@ -6,6 +6,10 @@ var debug = require('debug')('localtunnel'); var argv = optimist .usage('Usage: $0 --port [num]') + .options('secure', { + default: false, + describe: 'use this flag to indicate proxy over https' + }) .options('port', { default: '80', describe: 'listen on this port for outside requests' @@ -18,7 +22,8 @@ if (argv.help) { } var server = require('../server')({ - max_tcp_sockets: 5 + max_tcp_sockets: 5, + secure: argv.secure }); server.listen(argv.port, function() { diff --git a/server.js b/server.js index f9ab678..09583eb 100644 --- a/server.js +++ b/server.js @@ -119,6 +119,8 @@ function new_client(id, opt, cb) { module.exports = function(opt) { opt = opt || {}; + var schema = opt.secure ? 'https' : 'http'; + var app = express(); app.set('view engine', 'html'); @@ -154,7 +156,7 @@ module.exports = function(opt) { return res.end(err.message); } - var url = 'https://' + req_id + '.' + req.headers.host; + var url = schema + '://' + req_id + '.' + req.headers.host; info.url = url; res.end(JSON.stringify(info)); }); @@ -178,7 +180,7 @@ module.exports = function(opt) { return res.end(err.message); } - var url = 'https://' + req_id + '.' + req.headers.host; + var url = schema + '://' + req_id + '.' + req.headers.host; info.url = url; res.end(JSON.stringify(info)); });