Skip to content

Instantly share code, notes, and snippets.

@No9
Created May 28, 2012 21:11
Show Gist options
  • Save No9/2821229 to your computer and use it in GitHub Desktop.
Save No9/2821229 to your computer and use it in GitHub Desktop.
A sample implementation of trumpet in nodejistsu http-proxy
var http = require('http'),
httpProxy = require('http-proxy'),
trumpet = require('trumpet');
httpProxy.createServer(
function (req, res, next) {
var _write = res.write;
res.write = function (data) {
var tr = trumpet();
tr.select('.b', function (node) {
node.replace(function (html) {
return '<div>& Trumpet</div>';
});
});
tr.on('data', function (buf) {
_write.call(res, buf);
});
tr.write(data);
}
next();
},
9000, 'localhost'
).listen(8000);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<html><head></head><body><div class="a">Nodejitsu Http Proxy</div><div class="b">& Frames</div></body></html>');
res.end();
}).listen(9000);
@No9
Copy link
Author

No9 commented May 30, 2012

@dominictarr "you can also run tap tests just with node test/test.js" interesting - I didn't try that.
Given the fact you had a similar outcome I think I will stick where I am for now.
TTFN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment