harmon

A piece of middleware for node-http-proxy that allows you to modify the remote service response with trumpet

npm install harmon
2 downloads in the last day
28 downloads in the last week
51 downloads in the last month

harmon

A middleware component for node-http-proxy using trumpet to parse and transform the response from the proxied server.

build status

With apologies to connect-gzip

harmon

install

$ npm install harmon

examples

Overview


In this example the HTML below is returned from the remote server and parsed:

<html>
    <head></head>
    <body>
        <div class="a">Nodejitsu Http Proxy</div>
        <div class="b">&amp; Frames</div>
    </body>
</html>

The following line is removed:

<div class="b">&amp; Frames</div>

And is replaced with:

<div>+ Trumpet</div>

Run It!


from your project root:

$ cd node_modules/harmon/examples
$ node simple.js

Browse to localhost:8000 and you should see:

simple output

Code

var http = require('http'),
    connect = require('connect'),
    httpProxy = require('http-proxy');


var selects = [];
var simpleselect = {};

simpleselect.query = '.b';
simpleselect.func = function (node) {
    node.createWriteStream().end('<div>+ Trumpet</div>');
}

selects.push(simpleselect);

//
// Basic Connect App
//
connect.createServer(
  require('harmon')([], selects),
  function (req, res) {
    proxy.web(req, res);
  }
).listen(8000);

var proxy = httpProxy.createProxyServer({
   target: 'http://localhost:9000'
})

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">&amp; Frames</div></body></html>');
  res.end();
}).listen(9000);

or See how images could be rotated.

$ cd node_modules/harmon/examples
$ node rotate.js

See trumpet for the types of queries and functions you can

npm loves you