mirror of
https://github.com/bitinflow/localtunnel.git
synced 2026-03-15 06:25:55 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b67c8a8ce | ||
|
|
71552a336e | ||
|
|
87a23bf28c | ||
|
|
3d54de851f | ||
|
|
92bb807908 | ||
|
|
afbdc3697e | ||
|
|
0049f21b55 | ||
|
|
509841104b | ||
|
|
92caf2f204 |
@@ -27,14 +27,13 @@ var opt = {
|
|||||||
|
|
||||||
lt_client(opt.port, opt, function(err, tunnel) {
|
lt_client(opt.port, opt, function(err, tunnel) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
throw err;
|
||||||
return process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('your url is: %s', tunnel.url);
|
console.log('your url is: %s', tunnel.url);
|
||||||
|
|
||||||
tunnel.on('error', function(err) {
|
tunnel.on('error', function(err) {
|
||||||
console.error(err);
|
throw err;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
20
client.js
20
client.js
@@ -87,13 +87,13 @@ TunnelCluster.prototype.open = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function conn_local() {
|
function conn_local() {
|
||||||
debug('connecting locally to %s:%d', local_host, local_port);
|
|
||||||
|
|
||||||
if (remote.destroyed) {
|
if (remote.destroyed) {
|
||||||
|
debug('remote destroyed');
|
||||||
self.emit('dead');
|
self.emit('dead');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug('connecting locally to %s:%d', local_host, local_port);
|
||||||
remote.pause();
|
remote.pause();
|
||||||
|
|
||||||
// connection to local http server
|
// connection to local http server
|
||||||
@@ -103,19 +103,24 @@ TunnelCluster.prototype.open = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function remote_close() {
|
function remote_close() {
|
||||||
|
debug('remote close');
|
||||||
self.emit('dead');
|
self.emit('dead');
|
||||||
local.end();
|
local.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
remote.once('close', remote_close);
|
remote.once('close', remote_close);
|
||||||
|
|
||||||
local.on('error', function(err) {
|
// TODO some languages have single threaded servers which makes opening up
|
||||||
|
// multiple local connections impossible. We need a smarter way to scale
|
||||||
|
// and adjust for such instances to avoid beating on the door of the server
|
||||||
|
local.once('error', function(err) {
|
||||||
|
debug('local error %s', err.message);
|
||||||
local.end();
|
local.end();
|
||||||
|
|
||||||
remote.removeListener('close', remote_close);
|
remote.removeListener('close', remote_close);
|
||||||
|
|
||||||
if (err.code !== 'ECONNREFUSED') {
|
if (err.code !== 'ECONNREFUSED') {
|
||||||
return local.emit('error', err);
|
return remote.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrying connection to local server
|
// retrying connection to local server
|
||||||
@@ -146,8 +151,8 @@ TunnelCluster.prototype.open = function() {
|
|||||||
// tunnel is considered open when remote connects
|
// tunnel is considered open when remote connects
|
||||||
remote.once('connect', function() {
|
remote.once('connect', function() {
|
||||||
self.emit('open', remote);
|
self.emit('open', remote);
|
||||||
|
conn_local();
|
||||||
});
|
});
|
||||||
remote.once('connect', conn_local);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var Tunnel = function(opt) {
|
var Tunnel = function(opt) {
|
||||||
@@ -194,6 +199,11 @@ Tunnel.prototype._init = function(cb) {
|
|||||||
return setTimeout(get_url, 1000);
|
return setTimeout(get_url, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
var err = new Error((body && body.message) || 'localtunnel server returned an error, please try again');
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
var port = body.port;
|
var port = body.port;
|
||||||
var host = upstream.hostname;
|
var host = upstream.hostname;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"author": "Roman Shtylman <shtylman@gmail.com>",
|
"author": "Roman Shtylman <shtylman@gmail.com>",
|
||||||
"name": "localtunnel",
|
"name": "localtunnel",
|
||||||
"description": "expose localhost to the world",
|
"description": "expose localhost to the world",
|
||||||
"version": "1.1.0",
|
"version": "1.1.2",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/shtylman/localtunnel.git"
|
"url": "git://github.com/shtylman/localtunnel.git"
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"mocha": "~1.17.0"
|
"mocha": "~1.17.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --ui qunit --reporter list -- test/index.js"
|
"test": "mocha --ui qunit --reporter list --timeout 10000 -- test/index.js"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"lt": "./bin/client"
|
"lt": "./bin/client"
|
||||||
|
|||||||
Reference in New Issue
Block a user