-
-
Save No9/2821229 to your computer and use it in GitHub Desktop.
| 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); |
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
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 "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
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