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


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


$ npm install harmon

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

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

The following line is removed:

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

And is replaced with:

<div>+ Trumpet</div>

from your project root:

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

Browse to localhost:8000 and you should see:

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>');
        // Basic Connect App 
        var app = connect();
        var proxy = httpProxy.createProxyServer({
              target: 'http://localhost:9000'
        //Additional true parameter can be used to ignore js and css files.  
        //app.use(require('../')([], selects), true); 
        app.use(require('../')([], selects));
        app.use(function (reqres) {
                   proxy.web(req, res);
        http.createServer(function (reqres) {
             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>');

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 use.