mirror of
https://github.com/bitinflow/localtunnel.git
synced 2026-03-13 21:45:54 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
174e7f3982 | ||
|
|
44be55cd7b | ||
|
|
5c6cd2359c | ||
|
|
2f6f9459ad | ||
|
|
7217a08a05 | ||
|
|
fbfc923a7e | ||
|
|
d9bc11b520 | ||
|
|
ad64611bd1 | ||
|
|
ac70515143 | ||
|
|
8d7ccccf21 |
@@ -1,4 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- 0.9
|
||||
- "0.10"
|
||||
|
||||
7
History.md
Normal file
7
History.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# 1.0.0 / 2014-02-14
|
||||
|
||||
* default to localltunnel.me for host
|
||||
* remove exported `connect` method (just export one function that does the same thing)
|
||||
* change localtunnel signature to (port, opt, fn)
|
||||
|
||||
# 0.2.2 / 2014-01-09
|
||||
46
README.md
46
README.md
@@ -1,4 +1,4 @@
|
||||
# localtunnel #
|
||||
# localtunnel [](https://travis-ci.org/defunctzombie/localtunnel) #
|
||||
|
||||
localtunnel exposes your localhost to the world for easy testing and sharing! No need to mess with DNS or deploy just to have others test out your changes.
|
||||
|
||||
@@ -28,27 +28,41 @@ You can restart your local server all you want, ```lt``` is smart enough to dete
|
||||
|
||||
The localtunnel client is also usable through an API (for test integration, automation, etc)
|
||||
|
||||
### localtunnel(port [,opts], fn)
|
||||
|
||||
Creates a new localtunnel to the specified local `port`. `fn` will be called once you have been assigned a public localtunnel url. `opts` can be used to request a specific `subdomain`.
|
||||
|
||||
```javascript
|
||||
var localtunnel = require('localtunnel');
|
||||
|
||||
var client = localtunnel.connect({
|
||||
// the localtunnel server
|
||||
host: 'http://localtunnel.me',
|
||||
// your local application port
|
||||
port: 12345
|
||||
});
|
||||
localtunnel(port, function(err, tunnel) {
|
||||
if (err) ...
|
||||
|
||||
// when your are assigned a url
|
||||
client.on('url', function(url) {
|
||||
// you can now make http requests to the url
|
||||
// they will be proxied to your local server on port [12345]
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
// uh oh!
|
||||
// the assigned public url for your tunnel
|
||||
// i.e. https://abcdefgjhij.localtunnel.me
|
||||
tunnel.url;
|
||||
});
|
||||
```
|
||||
|
||||
### opts
|
||||
|
||||
* `subdomain` A *string* value requesting a specific subdomain on the proxy server. **Note** You may not actually receive this name depending on availablily.
|
||||
|
||||
### Tunnel
|
||||
|
||||
The `tunnel` instance returned to your callback emits the following events
|
||||
|
||||
|event|args|description|
|
||||
|----|----|----|
|
||||
|error|err|fires when an error happens on the tunnel|
|
||||
|close||fires when the tunnel has closed|
|
||||
|
||||
The `tunnel instance has the following methods
|
||||
|
||||
|method|args|description|
|
||||
|----|----|----|
|
||||
|close||close the tunnel|
|
||||
|
||||
## other clients ##
|
||||
|
||||
Clients in other languages
|
||||
@@ -57,7 +71,7 @@ Clients in other languages
|
||||
|
||||
## server ##
|
||||
|
||||
See shtylman/localtunnel-server for details on the server that powers localtunnel.
|
||||
See defunctzombie/localtunnel-server for details on the server that powers localtunnel.
|
||||
|
||||
## License ##
|
||||
MIT
|
||||
|
||||
16
bin/client
16
bin/client
@@ -25,15 +25,17 @@ var opt = {
|
||||
subdomain: argv.subdomain,
|
||||
}
|
||||
|
||||
var client = lt_client.connect(opt);
|
||||
lt_client(opt.port, opt, function(err, tunnel) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
// only emitted when the url changes
|
||||
client.on('url', function(url) {
|
||||
console.log('your url is: %s', url);
|
||||
});
|
||||
console.log('your url is: %s', tunnel.url);
|
||||
|
||||
client.on('error', function(err) {
|
||||
console.error(err);
|
||||
tunnel.on('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
// vim: ft=javascript
|
||||
|
||||
30
client.js
30
client.js
@@ -72,7 +72,6 @@ TunnelCluster.prototype.open = function() {
|
||||
|
||||
function remote_close() {
|
||||
self.emit('dead');
|
||||
local.unpipe();
|
||||
local.end();
|
||||
};
|
||||
|
||||
@@ -117,7 +116,9 @@ var Tunnel = function(opt) {
|
||||
|
||||
var self = this;
|
||||
self._closed = false;
|
||||
self._opt = opt;
|
||||
self._opt = opt || {};
|
||||
|
||||
self._opt.host = self._opt.host || 'https://localtunnel.me';
|
||||
};
|
||||
|
||||
Tunnel.prototype.__proto__ = EventEmitter.prototype;
|
||||
@@ -221,15 +222,17 @@ Tunnel.prototype._establish = function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
Tunnel.prototype.open = function() {
|
||||
Tunnel.prototype.open = function(cb) {
|
||||
var self = this;
|
||||
|
||||
self._init(function(err, info) {
|
||||
if (err) {
|
||||
return self.emit('error', err);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
self.url = info.url;
|
||||
self._establish(info);
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -241,8 +244,21 @@ Tunnel.prototype.close = function() {
|
||||
self.emit('close');
|
||||
};
|
||||
|
||||
module.exports.connect = function(opt) {
|
||||
module.exports = function localtunnel(port, opt, fn) {
|
||||
if (typeof opt === 'function') {
|
||||
fn = opt;
|
||||
opt = {};
|
||||
}
|
||||
|
||||
opt = opt || {};
|
||||
opt.port = port;
|
||||
|
||||
var client = Tunnel(opt);
|
||||
client.open();
|
||||
return client;
|
||||
client.open(function(err) {
|
||||
if (err) {
|
||||
return fn(err);
|
||||
}
|
||||
|
||||
fn(null, client);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"author": "Roman Shtylman <shtylman@gmail.com>",
|
||||
"name": "localtunnel",
|
||||
"description": "expose localhost to the world",
|
||||
"version": "0.2.1",
|
||||
"version": "1.0.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/shtylman/localtunnel.git"
|
||||
@@ -12,7 +12,12 @@
|
||||
"optimist": "0.3.4",
|
||||
"debug": "0.7.4"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
"mocha": "~1.17.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --ui qunit --reporter list -- test/index.js"
|
||||
},
|
||||
"bin": {
|
||||
"lt": "./bin/client"
|
||||
},
|
||||
|
||||
69
test/index.js
Normal file
69
test/index.js
Normal file
@@ -0,0 +1,69 @@
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var url = require('url');
|
||||
var assert = require('assert');
|
||||
|
||||
var localtunnel = require('../');
|
||||
|
||||
test('setup local http server', function(done) {
|
||||
var server = http.createServer();
|
||||
server.on('request', function(req, res) {
|
||||
res.write('foo');
|
||||
res.end();
|
||||
});
|
||||
server.listen(function() {
|
||||
var port = server.address().port;
|
||||
|
||||
test._fake_port = port;
|
||||
console.log('local http on:', port);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('setup localtunnel client', function(done) {
|
||||
localtunnel(test._fake_port, function(err, tunnel) {
|
||||
assert.ifError(err);
|
||||
assert.ok(new RegExp('^https:\/\/.*localtunnel.me' + '$').test(tunnel.url));
|
||||
test._fake_url = tunnel.url;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('query localtunnel server w/ ident', function(done) {
|
||||
var uri = test._fake_url;
|
||||
var parsed = url.parse(uri);
|
||||
|
||||
var opt = {
|
||||
host: parsed.host,
|
||||
port: 443,
|
||||
headers: {
|
||||
host: parsed.hostname
|
||||
},
|
||||
path: '/'
|
||||
};
|
||||
|
||||
var req = https.request(opt, function(res) {
|
||||
res.setEncoding('utf8');
|
||||
var body = '';
|
||||
|
||||
res.on('data', function(chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
assert.equal('foo', body);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
req.end();
|
||||
});
|
||||
|
||||
test('request specific domain', function(done) {
|
||||
localtunnel(test._fake_port, { subdomain: 'abcd' }, function(err, tunnel) {
|
||||
assert.ifError(err);
|
||||
assert.ok(new RegExp('^https:\/\/abcd.localtunnel.me' + '$').test(tunnel.url));
|
||||
tunnel.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user