Permalink
Browse files

Adding Browserstack tunnel. Improving docs.

  • Loading branch information...
1 parent d8a5316 commit cf03016a1bf62fd77077743bfc34809f54dca70e @daffl committed Nov 15, 2012
View
@@ -13,4 +13,3 @@ results
node_modules
npm-debug.log
-.idea
View
@@ -2,6 +2,7 @@ var os = require('os');
exports.localtunnel = require('./services/localtunnel');
exports.pagekite = require('./services/pagekite');
+exports.browserstack = require('./services/browserstack');
exports.local = function(config, callback) {
var hostname = config.hostname || (config.useOsHostname ? os.hostname() : 'localhost');
var url = 'http://' + hostname + (config.port ? ':' + config.port : '');
@@ -0,0 +1,50 @@
+// http://www.browserstack.com/local-testing#cmd-tunnel
+// java -jar BrowserStackTunnel.jar <KEY> host1,port1,ssl_flag,host2,port2,ssl_flag...
+// java -jar BrowserStackTunnel.jar CuCzN6aEMzLAei1izNLR localhost,3000,0
+
+// http://www.browserstack.com/BrowserStackTunnel.jar
+var spawn = require('child_process').spawn;
+var winston = require('winston');
+var fs = require('fs');
+
+module.exports = function (config, callback) {
+ var jarFile = __dirname + '/../../resources/BrowserStackTunnel.jar';
+ var options = {
+ host : config.host || 'localhost',
+ port : config.port || 80,
+ ssl : config.ssl || 0
+ };
+ var cb = function() {
+ if(callback) {
+ callback.apply(this, arguments);
+ callback = null;
+ }
+ };
+ var flags = [options.host, options.port, options.ssl].join(',');
+ var browserstack = spawn(config.java || 'java', [ '-jar', jarFile, config.key, flags]);
+
+ var buffer = '';
+ var timeout = setTimeout(function() {
+ browserstack.kill();
+ cb(new Error('Process timed out'));
+ }, config.timeout || 30000);
+
+ browserstack.on('exit', function(code) {
+ if(code !== 0) {
+ cb(new Error('Process exited with ' + code + '\n'));
+ }
+ });
+
+ browserstack.stdout.on('data', function(data) {
+ buffer += data.toString();
+ var matches = buffer.match(new RegExp('.*localhost:' + options.port + '.*'));
+ if(matches !== null) {
+ clearTimeout(timeout);
+ cb(null, matches[0], browserstack);
+ }
+ });
+
+ browserstack.stderr.on('data', function(data) {
+ winston.error('BROWSERSTACK ERROR: ' + data.toString());
+ });
+}
@@ -50,7 +50,9 @@ module.exports = function(config, callback) {
pid : localtunnel.pid
});
- localtunnel.stdout.pipe(process.stdout, { end : false });
+ if(config.pipe) {
+ localtunnel.stdout.pipe(process.stdout, { end : false });
+ }
localtunnel.on('exit', function(code) {
if( code === 127 && runInstaller) {
View
@@ -28,7 +28,7 @@ module.exports = function(config, callback) {
// winston.debug('PAGEKITE: ' + data.toString());
if(buffer.match(new RegExp('bid=http:' + url)) !== null) {
clearTimeout(timeout);
- cb(null, 'http://' + url, pagekite, pagekite);
+ cb(null, 'http://' + url, pagekite);
}
});
View
@@ -3,10 +3,18 @@
"description": "Localhost tunelling service wrappers",
"version": "0.1.0",
"homepage": "http://github.com/daffl/miner",
- "author": "David Luecke",
+ "author" : {
+ "name" : "David Luecke",
+ "email" : "daff@neyeon.com",
+ "web" : "http://daffl.github.com"
+ },
"main": "lib/miner.js",
"engines": {
- "node": "~0.6"
+ "node": "~0.8"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "git@github.com:daffl/miner.git"
},
"devDependencies" : {
"mocha" : ">= 1.4.0",
View
@@ -1,7 +1,7 @@
# Miner
Miner wraps localhost tunelling services to easily expose your Node server to the web.
-The default service interface looks like this:
+The Miner service interface looks like this:
```javascript
var miner = require('miner');
@@ -15,11 +15,40 @@ The default service interface looks like this:
See the [ChildProcess documentation](http://nodejs.org/api/child_process.html#child_process_class_childprocess)
for more information about the `process` object.
-Currently supported services:
+## Quick Start
-## Default tunnel
+Lets create the basic NodeJS HTTP server example and make it available to the web via
+[Localtunnel](http://progrium.com/localtunnel/):
-Use the default tunnel to access your localhost through the Miner interface using the following options:
+ var http = require('http');
+ var miner = require('miner');
+ var port = 1337;
+
+ http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('Hello World\n');
+ }).listen(port, '127.0.0.1');
+ console.log('Server running at http://127.0.0.1:1337/');
+
+ miner.localtunnel({
+ port: port
+ }, function(error, url, process) {
+ if(error) {
+ console.log('ERROR', error);
+ return;
+ }
+ console.log('Your server is now available to the world at:');
+ console.log(url);
+ });
+
+Just visit the url to see the server output.
+
+## Tunneling services
+
+### Default tunnel
+
+The default tunnel is a dummy tunelling service that returns the URL for a given hostname and port. That way you
+can use the miner interface even when just connecting to a local server.
* `port` - The port to share (default: none `80`)
* `hostname` - The hostname to use (default: `localhost`)
@@ -29,12 +58,12 @@ Use the default tunnel to access your localhost through the Miner interface usin
var miner = require('miner');
miner.local({
port : 8080
- }, function(error, url, process) {
+ }, function(error, url) {
url // -> http://localhost:8080
});
```
-## Localtunnel
+### Localtunnel
[Localtunnel](http://localtunnel.com) is a free localhost tunelling service. Ruby and the `gem` command need
to be in your path for it to work. If the Gem is not installed it will be installed automatically.
@@ -56,7 +85,7 @@ it hasn't reported back a valid URL (default: `30000`)
});
```
-## Pagekite
+### Pagekite
[Pagekite](https://pagekite.net/) is a reliable way to make localhost part of the Web.
Sign up for the free one month trial [here](https://pagekite.net/signup/).
@@ -81,6 +110,28 @@ it hasn't reported back a valid URL (default: `30000`)
```
-## Showoff.io
+### Browserstack
+
+[BrowserStack](http://browserstack.com) is a cross browser testing tool. With their API it also provides
+[command line tunneling](http://www.browserstack.com/local-testing#cmd-tunnel).
+You need a Browserstack account with API access and have to provide your
+[private key](http://www.browserstack.com/local-testing#cmd-tunnel) to the miner service. Unlike other
+services it will not provide a publicly acessible URL but the given URL will be accessible on your BrowserStack
+ instances.
- // TODO
+* `key` - Your browserstack command line tunnel key
+* `host` - The hostname to share another internal server (default: `localhost`)
+* `port` - The port to share (default: `80`)
+* `timeout` - The timeout (in *ms*) after which the process will be killed if
+* `ssl` - The optional SSL port (default: `0`)
+it hasn't reported back a valid URL (default: `30000`)
+* `java` - The java executable (default: `java`)
+
+```javascript
+ var miner = require('miner');
+ miner.browserstack({
+ port : 8080
+ }, function(error, url, process) {
+ process.kill();
+ });
+```
Binary file not shown.
File renamed without changes.
View
@@ -1,9 +0,0 @@
-var test = require('./lib/services/pagekite');
-
-test({ name : 'daff' }, function(err, url, process) {
- console.log('Pagekite started, go to ' + url);
- setTimeout(function() {
- console.log('killing process');
- process.kill();
- }, 10000);
-});

0 comments on commit cf03016

Please sign in to comment.