Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

render browser output back to the terminal

  • Loading branch information...
commit 11b72c1e5b1b7f6139ea72702a76154edb81a458 1 parent df888ca
@substack authored
View
45 bin/cmd.js
@@ -1,26 +1,41 @@
#!/usr/bin/env node
+var shoe = require('shoe');
+var http = require('http');
+var ecstatic = require('ecstatic')(__dirname + '/../static');
var argv = require('optimist').argv;
+var mkdirp = require('mkdirp');
+var insertProxy = require('../lib/proxy');
//var profileDir = '/tmp/' + Math.random().toString(16).slice(2);
var profileDir = '/tmp/02faf1b1';
-var mkdirp = require('mkdirp').sync(profileDir);
+mkdirp.sync(profileDir);
-var script = '<script src="http://localhost:9595/proxy.js"></script>';
-var insertProxy = require('../lib/proxy');
+var port = {
+ proxy : 54045,
+ server : 54046
+};
-var port = 54045;
-var proxy = insertProxy(script, [ 'http://localhost:9595' ]);
-proxy.listen(port);
+var script = '<script src="http://localhost:'
+ + port.server
+ + '/proxy.js"></script>'
+;
+var proxy = insertProxy(script, [ 'http://localhost:' + port.server ]);
+proxy.listen(port.proxy);
-var http = require('http');
-var ecstatic = require('ecstatic')(__dirname + '/../static');
var server = http.createServer(ecstatic);
-server.listen(9595);
-console.log([
- 'no_proxy=""',
+server.listen(port.server);
+
+var sock = shoe(function (stream) {
+ stream.pipe(process.stdout, { end : false });
+});
+sock.install(server, '/push');
+
+var spawn = require('child_process').spawn;
+var args = [
'google-chrome',
- '--incognito',
- '--proxy-server=localhost:' + port,
+ '--proxy-server=localhost:' + port.proxy,
'--user-data-dir=' + profileDir,
- 'http://localhost:9595'
-].join(' '));
+ 'http://localhost:' + port.server
+];
+console.log(args.join(' '));
+//spawn('xvfb-run', args, { env : { no_proxy : '' } });
View
38 browser/output.js
@@ -1,33 +1,11 @@
var Stream = require('stream');
-var domready = require('domready');
-var json = typeof JSON === 'object' ? JSON : require('jsonify');
+var render = require('./render');
+var JSONStream = require('JSONStream');
-var stream = module.exports = new Stream;
-stream.writable = true;
+var push = JSONStream.stringify();
+push.pipe(require('shoe')('/push'));
-var ready = false;
-var buffered = [];
-domready(function () {
- ready = true;
- buffered.forEach(function (msg) {
- stream.write(msg);
- });
- buffered = [];
-});
-
-stream.write = function (msg) {
- if (!ready) {
- buffered.push(msg);
- return;
- }
-
- var div = document.createElement('div');
- var txt = document.createTextNode(json.stringify(msg));
- div.appendChild(txt);
- document.body.appendChild(div);
-};
-
-stream.end = function (msg) {
- if (msg !== undefined) stream.write(msg);
- stream.writable = false;
-};
+var es = require('event-stream');
+var stream = module.exports = es.through();
+stream.pipe(render);
+stream.pipe(push);
View
33 browser/render.js
@@ -0,0 +1,33 @@
+var Stream = require('stream');
+var domready = require('domready');
+var json = typeof JSON === 'object' ? JSON : require('jsonify');
+
+var stream = module.exports = new Stream;
+stream.writable = true;
+
+var ready = false;
+var buffered = [];
+domready(function () {
+ ready = true;
+ buffered.forEach(function (msg) {
+ stream.write(msg);
+ });
+ buffered = [];
+});
+
+stream.write = function (msg) {
+ if (!ready) {
+ buffered.push(msg);
+ return;
+ }
+
+ var div = document.createElement('div');
+ var txt = document.createTextNode(json.stringify(msg));
+ div.appendChild(txt);
+ document.body.appendChild(div);
+};
+
+stream.end = function (msg) {
+ if (msg !== undefined) stream.write(msg);
+ stream.writable = false;
+};
View
17 lib/proxy.js
@@ -1,14 +1,27 @@
var http = require('http');
var bouncy = require('bouncy');
+var Stream = require('stream');
module.exports = function (insert, skip) {
if (!Buffer.isBuffer(insert)) insert = new Buffer(insert);
skip = skip.map(function (s) { return s.replace(/\/*$/, '/') });
- return bouncy(createServer.bind(null, insert, skip));
+
+ var server = bouncy(function (req, bounce) {
+ return createServer.call(server, insert, skip, req, bounce);
+ });
+ var log = server.log = new Stream;
+ log.readable = true;
+ server.on('close', function () { log.emit('end') });
+ return server;
};
function createServer (insert, skip, req, bounce) {
- console.log(req.method + ' ' + req.url);
+ this.log.emit('data', {
+ method : req.method,
+ url : req.url,
+ headers : req.headers,
+ data : req
+ });
if (req.method === 'CONNECT') {
bounce.reset();
View
5 package.json
@@ -28,7 +28,10 @@
"optimist" : "~0.3.4",
"mkdirp" : "~0.3.3",
"tap" : "~0.2.5",
- "browserify" : "~1.13.1"
+ "browserify" : "~1.13.1",
+ "shoe" : "~0.0.0",
+ "event-stream" : "~2.0.4",
+ "JSONStream" : "~0.3.0"
},
"engines" : {
"node" : ">=0.6"
Please sign in to comment.
Something went wrong with that request. Please try again.