Skip to content

Instantly share code, notes, and snippets.

@No9
Created May 28, 2012 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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);
@jfhbrook
Copy link

That's pretty cool. Make it a module and whip up some upside-down-ternet-like examples and you're golden!

@No9
Copy link
Author

No9 commented May 29, 2012

Thanks for the feedback @jesusabdullah
I made it a piece of middleware based on the gzip approach.
https://github.com/No9/harmon
I kept the simple example for now and I am off to find out the best approach to testing this type of gig on travis.ci

@dominictarr
Copy link

this is what I came up with when I needed to test a proxy: https://github.com/dominictarr/balancer/blob/master/test/proxy-test.js

@No9
Copy link
Author

No9 commented May 29, 2012

Thanks @dominictarr
I tried hard to get tap up and running even followed @isaacs very detailed sample.
https://github.com/isaacs/node-tap/blob/master/example/test/test-example.js
I got the plans and test http server up no problems but I couldn't prevent http-proxy hanging :(
I tried it without my middleware even killing the process when the tests had complete and all sorts of shenanigans in between but to no avail.
So I have resorted back to plain old assert and I am happy.
Anyway onto making some funky samples to test out some use cases.
Thanks Again

@dominictarr
Copy link

dominictarr commented May 30, 2012 via email

@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