A middleware component for using
to parse and transform the response from the proxied server.
This is a basic example of the module. It replaces
<div class="b">& Frames</div>
with
<div>+ Trumpet</div>
To run it
$ cd examples
$ node simple.js
var http = require('http'),
httpProxy = require('http-proxy');
// Create an array of selects that harmon will process.
var actions = [];
// Create a simple action
var simpleaction = {};
// Select a node by its class name. You can also select by tag e.g. 'div'
simpleaction.query = '.b';
// Create an function that is executed when that node is selected. Here we just replace '& frames' with '+trumpet'
simpleaction.func = function (node) {
node.replace(function (html) {
return '<div>+ Trumpet</div>';
});
}
// Add the action to the action array
actions.push(simpleaction);
// Create a node-http-proxy configured with our harmon middleware
httpProxy.createServer(
require('../').harmon(selects),
9000, 'localhost'
).listen(8000);
// Create a simple web server for the proxy to send requests to and manipulate the data from
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);