bugfix: show success, not just error

Bu işleme şunda yer alıyor:
AJ ONeal 2018-06-30 13:20:00 -06:00
ebeveyn 90fda2ac98
işleme 7a36b1af8a
2 değiştirilmiş dosya ile 37 ekleme ve 12 silme

Dosyayı Görüntüle

@ -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);
};

Dosyayı Görüntüle

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