From e0690e5e8a16c3cc49a94bad6d73bf27a3ce50f7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 15 Oct 2016 02:18:30 -0400 Subject: [PATCH] correctly handle redirect --- package.json | 1 + wstunneld.js | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a1e8478..a775cb0 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "commander": "^2.9.0", "jsonwebtoken": "^7.1.9", "localhost.daplie.com-certificates": "^1.2.3", + "redirect-https": "^1.1.0", "sni": "^1.0.0", "tunnel-packer": "^1.0.0", "ws": "^1.1.1" diff --git a/wstunneld.js b/wstunneld.js index 7b2f397..74fd489 100644 --- a/wstunneld.js +++ b/wstunneld.js @@ -55,6 +55,7 @@ module.exports.create = function (copts) { }); remote = remote || {}; token.domains.forEach(function (domainname) { + console.log('domainname', domainname); remotes[domainname] = remote; }); var handlers = { @@ -135,7 +136,7 @@ module.exports.create = function (copts) { function connectHttp(servername, socket) { console.log("connectHttp('" + servername + "', socket)"); socket.__my_servername = servername; - httpServer.emit('connection', socket); + redirectServer.emit('connection', socket); } function connectHttps(servername, socket) { @@ -321,7 +322,12 @@ module.exports.create = function (copts) { var remotes = {}; var selfnames = copts.servernames; var secret = copts.secret; + var redirectHttps = require('redirect-https')(); + var redirectServer = http.createServer(function (req, res) { + res.setHeader('Connection', 'close'); + redirectHttps(req, res); + }); var httpServer = http.createServer(function (req, res) { console.log('req.socket.encrypted', req.socket.encrypted); res.end('Hello, World!');