6 Commits

Author SHA1 Message Date
Roman Shtylman
a9b0274ff4 0.1.3 2013-11-14 12:10:02 -05:00
Roman Shtylman
83ecb29eff Merge pull request #26 from EverythingMe/override_localhost
Added the --localhost parameter to tunnel the traffic to other hosts
2013-11-14 09:08:47 -08:00
Omri Bahumi
21df257d16 Added the --local-host parameter to tunnel the traffic to other hosts 2013-11-14 18:06:19 +02:00
Roman Shtylman
18ada0854a 0.1.2 2013-11-06 23:25:28 -05:00
Roman Shtylman
34afd6537d more resilient to upstream server failure and restart 2013-11-06 23:25:05 -05:00
Roman Shtylman
2c38aefb9d add go client to readme 2013-10-23 11:31:28 -04:00
4 changed files with 52 additions and 26 deletions

View File

@@ -49,6 +49,12 @@ client.on('error', function(err) {
});
```
## other clients ##
Clients in other languages
*go* [gotunnelme](https://github.com/NoahShen/gotunnelme)
## server ##
See shtylman/localtunnel-server for details on the server that powers localtunnel.

View File

@@ -11,12 +11,17 @@ var argv = require('optimist')
.options('subdomain', {
describe: 'request this subdomain'
})
.options('local-host', {
describe: 'tunnel traffic to this host instead of localhost'
})
.default('local-host', 'localhost')
.describe('port', 'internal http server port')
.argv;
var opt = {
host: argv.host,
port: argv.port,
local_host: argv['local-host'],
subdomain: argv.subdomain,
}

View File

@@ -2,6 +2,7 @@ var net = require('net');
var url = require('url');
var EventEmitter = require('events').EventEmitter;
var after = require('after');
var request = require('request');
// request upstream url and connection info
@@ -18,6 +19,9 @@ var request_url = function(params, cb) {
var connect = function(opt) {
var ev = new EventEmitter();
// local host
var local_host = opt.local_host;
// local port
var local_port = opt.port;
@@ -30,7 +34,7 @@ var connect = function(opt) {
var assigned_domain = opt.subdomain;
// connect to upstream given connection parameters
var tunnel = function (remote_host, remote_port) {
var tunnel = function (remote_host, remote_port, dead) {
var remote_opt = {
host: remote_host,
@@ -38,7 +42,7 @@ var connect = function(opt) {
};
var local_opt = {
host: 'localhost',
host: local_host,
port: local_port
};
@@ -49,9 +53,9 @@ var connect = function(opt) {
return;
}
// we need a new tunnel
if (++remote_attempts >= 3) {
console.error('localtunnel server offline - try again');
process.exit(-1);
return dead();
}
// connection to localtunnel server
@@ -108,32 +112,42 @@ var connect = function(opt) {
// where to quest
params.uri = base_uri + ((assigned_domain) ? assigned_domain : '?new');
// get an id from lt server and setup forwarding tcp connections
request_url(params, function(err, body) {
function init_tunnel() {
// get an id from lt server and setup forwarding tcp connections
request_url(params, function(err, body) {
if (err) {
ev.emit('error', new Error('tunnel server not available: ' + err.message + ', retry 1s'));
if (err) {
ev.emit('error', new Error('tunnel server not available: %s, retry 1s', err.message));
// retry interval for id request
return setTimeout(function() {
init_tunnel();
}, 1000);
}
// retry interval for id request
return setTimeout(function() {
connect_proxy(opt);
}, 1000);
}
// our assigned hostname and tcp port
var port = body.port;
var host = upstream.hostname;
// our assigned hostname and tcp port
var port = body.port;
var host = upstream.hostname;
// store the id so we can try to get the same one
assigned_domain = body.id;
// store the id so we can try to get the same one
assigned_domain = body.id;
var max_conn = body.max_conn_count || 1;
var max_conn = body.max_conn_count || 1;
for (var count = 0 ; count < max_conn ; ++count) {
tunnel(host, port);
}
// after all our tunnels die, we ask for new ones
// this might happen if the upstream server dies
var dead = after(max_conn, function() {
init_tunnel();
});
ev.emit('url', body.url);
});
for (var count = 0 ; count < max_conn ; ++count) {
tunnel(host, port, dead);
}
ev.emit('url', body.url);
});
}
init_tunnel();
return ev;
};

View File

@@ -2,14 +2,15 @@
"author": "Roman Shtylman <shtylman@gmail.com>",
"name": "localtunnel",
"description": "expose localhost to the world",
"version": "0.1.1",
"version": "0.1.3",
"repository": {
"type": "git",
"url": "git://github.com/shtylman/localtunnel.git"
},
"dependencies": {
"request": "2.11.4",
"optimist": "0.3.4"
"optimist": "0.3.4",
"after": "0.8.1"
},
"devDependencies": {},
"bin": {