add some tunnel support

This commit is contained in:
AJ ONeal 2016-10-11 13:41:29 -06:00
parent fa730f04b3
commit fa0990b02f
2 changed files with 34 additions and 1 deletions

30
lib/tunnel.js Normal file
View File

@ -0,0 +1,30 @@
'use strict';
module.exports.create = function (opts/*, servers*/) {
// servers = { plainserver, server }
var tunnel = require('daplie-tunnel');
var stunnel = require('stunnel');
return tunnel.token({
refreshToken: opts.refreshToken
, email: opts.email
, domains: [ opts.servername ]
}).then(function (result) {
// { jwt, tunnelUrl }
stunnel.connect({
token: result.jwt
, stunneld: result.tunnelUrl
, locals: [
{ protocol: 'https'
, hostname: opts.servername
, port: opts.port
}
, { protocol: 'http'
, hostname: opts.servername
, port: opts.insecurePort || opts.port
}
]
});
});
};

View File

@ -181,7 +181,7 @@ function createServer(port, pubdir, content, opts) {
server.on('request', function (req, res) { server.on('request', function (req, res) {
console.log('[' + req.method + '] ' + req.url); console.log('[' + req.method + '] ' + req.url);
if (!req.socket.encrypted) { if (!req.socket.encrypted && !/\/\.well-known\/acme-challenge\//.test(req.url)) {
opts.redirectApp(req, res); opts.redirectApp(req, res);
return; return;
} }
@ -424,6 +424,9 @@ function run() {
} }
}); });
} }
else {
require('./lib/tunnel.js').create(opts);
}
Object.keys(opts.ifaces).forEach(function (iname) { Object.keys(opts.ifaces).forEach(function (iname) {
var iface = opts.ifaces[iname]; var iface = opts.ifaces[iname];