mirror of
https://github.com/bitinflow/localtunnel.git
synced 2026-03-15 14:35:54 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18ada0854a | ||
|
|
34afd6537d | ||
|
|
2c38aefb9d |
@@ -49,6 +49,12 @@ client.on('error', function(err) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## other clients ##
|
||||||
|
|
||||||
|
Clients in other languages
|
||||||
|
|
||||||
|
*go* [gotunnelme](https://github.com/NoahShen/gotunnelme)
|
||||||
|
|
||||||
## server ##
|
## server ##
|
||||||
|
|
||||||
See shtylman/localtunnel-server for details on the server that powers localtunnel.
|
See shtylman/localtunnel-server for details on the server that powers localtunnel.
|
||||||
|
|||||||
57
client.js
57
client.js
@@ -2,6 +2,7 @@ var net = require('net');
|
|||||||
var url = require('url');
|
var url = require('url');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
|
var after = require('after');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
|
||||||
// request upstream url and connection info
|
// request upstream url and connection info
|
||||||
@@ -30,7 +31,7 @@ var connect = function(opt) {
|
|||||||
var assigned_domain = opt.subdomain;
|
var assigned_domain = opt.subdomain;
|
||||||
|
|
||||||
// connect to upstream given connection parameters
|
// connect to upstream given connection parameters
|
||||||
var tunnel = function (remote_host, remote_port) {
|
var tunnel = function (remote_host, remote_port, dead) {
|
||||||
|
|
||||||
var remote_opt = {
|
var remote_opt = {
|
||||||
host: remote_host,
|
host: remote_host,
|
||||||
@@ -49,9 +50,9 @@ var connect = function(opt) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we need a new tunnel
|
||||||
if (++remote_attempts >= 3) {
|
if (++remote_attempts >= 3) {
|
||||||
console.error('localtunnel server offline - try again');
|
return dead();
|
||||||
process.exit(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// connection to localtunnel server
|
// connection to localtunnel server
|
||||||
@@ -108,32 +109,42 @@ var connect = function(opt) {
|
|||||||
// where to quest
|
// where to quest
|
||||||
params.uri = base_uri + ((assigned_domain) ? assigned_domain : '?new');
|
params.uri = base_uri + ((assigned_domain) ? assigned_domain : '?new');
|
||||||
|
|
||||||
// get an id from lt server and setup forwarding tcp connections
|
function init_tunnel() {
|
||||||
request_url(params, function(err, body) {
|
// 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) {
|
// retry interval for id request
|
||||||
ev.emit('error', new Error('tunnel server not available: %s, retry 1s', err.message));
|
return setTimeout(function() {
|
||||||
|
init_tunnel();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// retry interval for id request
|
// our assigned hostname and tcp port
|
||||||
return setTimeout(function() {
|
var port = body.port;
|
||||||
connect_proxy(opt);
|
var host = upstream.hostname;
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// our assigned hostname and tcp port
|
// store the id so we can try to get the same one
|
||||||
var port = body.port;
|
assigned_domain = body.id;
|
||||||
var host = upstream.hostname;
|
|
||||||
|
|
||||||
// store the id so we can try to get the same one
|
var max_conn = body.max_conn_count || 1;
|
||||||
assigned_domain = body.id;
|
|
||||||
|
|
||||||
var max_conn = body.max_conn_count || 1;
|
// after all our tunnels die, we ask for new ones
|
||||||
for (var count = 0 ; count < max_conn ; ++count) {
|
// this might happen if the upstream server dies
|
||||||
tunnel(host, port);
|
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;
|
return ev;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
"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": "0.1.1",
|
"version": "0.1.2",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/shtylman/localtunnel.git"
|
"url": "git://github.com/shtylman/localtunnel.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"request": "2.11.4",
|
"request": "2.11.4",
|
||||||
"optimist": "0.3.4"
|
"optimist": "0.3.4",
|
||||||
|
"after": "0.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Reference in New Issue
Block a user