Skip to content
/ harmon Public

middleware for node-http-proxy to modify the remote website response with trumpet

License

Notifications You must be signed in to change notification settings

No9/harmon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 substack & nodejitsu

harmon

examples

simple

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

Browse to localhost:8000 and you should see:

simple output

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); 

See trumpet for the types of queries and functions you can pass.

About

middleware for node-http-proxy to modify the remote website response with trumpet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published