bugfix: show success, not just error

This commit is contained in:
AJ ONeal 2018-06-30 13:20:00 -06:00
parent 90fda2ac98
commit 7a36b1af8a
2 changed files with 37 additions and 12 deletions

View File

@ -0,0 +1,19 @@
'use strict';
module.exports = function (opts) {
console.log("Could not connect");
var socket = opts.socket;
var handler = opts.handler;
var http = require('http');
var server = http.createServer(function (req, res) {
console.log('responding to thing');
res.statusCode = 500;
res.setHeader('Content-Type', 'text/html');
res.end("<html>"
+ "<head><title>Couldn't Connect</title></head>"
+ "<body>Could not connect to localhost:" + handler + "</body>"
+ "</html>");
});
//server.emit('connection', socket);
socket.end("Could not connect to localhost:" + handler);
};

View File

@ -113,16 +113,19 @@ module.exports.assign = function (state, tun, cb) {
, remoteAddress: tun.address
, remotePort: tun.port
};
var conn = net.createConnection(netOpts, function () {
var conn = net.createConnection(netOpts);
conn.once('connect', function () {
// this will happen before 'data' or 'readable' is triggered
// We use the data from the netOpts object so that the createConnection function has
// the oppurtunity of removing/changing it if it wants/needs to handle it differently.
cb(null, conn);
cb = function () {}; // for error events
});
conn.on('error', function (err) {
cb(err);
conn.removeListener('error', onError);
});
function onError(err) {
if (cb) { cb(err); }
}
conn.on('error', onError);
return conn;
}
function redirectHttp(cb) {
@ -237,18 +240,21 @@ module.exports.assign = function (state, tun, cb) {
function invokeHandler(conf, tlsSocket, tun, id) {
if (parseInt(conf.handler, 10)) {
// TODO http-proxy with proper headers and ws support
getNetConn(conf.handler, function (err, conn) {
//tlsSocket.pause();
var conn = getNetConn(conf.handler, function (err/*, conn*/) {
if (err) {
// TODO direct to site with error page
console.error("probably couldn't connect to handler");
tlsSocket.write("Couldn't connect to localhost:" + conf.handler);
tlsSocket.end();
console.log("[DEBUG] need to handle error");
require('./handlers/local-app-error.js')({ handler: conf.handler, socket: tlsSocket });
return;
}
console.info("Port-Forwarding '" + (tun.name || tun.serviceport) + "' to '" + conf.handler + "'");
conn.pipe(tlsSocket);
tlsSocket.pipe(conn);
//conn.pipe(tlsSocket);
//tlsSocket.pipe(conn);
//tlsSocket.resume();
});
conn.pipe(tlsSocket);
tlsSocket.pipe(conn);
tlsSocket.resume();
return;
}
var handle = tun.name || tun.port;