Patron 
Wrapper around node-http-proxy with plugins, logging, and simple
configuration format.
Install
npm install patron
Example
var createProxyServer = require('patron');
var router = {
'example.com/con': 'localhost:3000',
'example.com/bar': 'localhost:4000',
'example.com/foo': {to: 'localhost:5000', ws:true},
'example.com': 'localhost:6780',
'blabla.com': {to: 'localhost:6000', ws:true, http: false},
'another.net': function(net, proxy) {
if (net.req.url == '/bla') {
return proxy(net, 'localhost:6778')
}
else if (net.req.url == '/test') {
net.req.url = '/rewrite/url'
return proxy(net, 'localhost:6712')
}
},
'anotherone.org': function(net, proxy) {
return net.res.end('Error')
}
}
createProxyServer(router).listen(80)
Explanations
Configuration
Router is an object where key is rule and value is action.
Rule is always a string. Host with or without url part
Action can be:
- simple string like
host:port
- object like {to: 'host:port', ws:true, http:false}
by default ws is false, http is true
- function, witch accepts 2 arguments
- object net {req:http.request, res:http.responce, protocol:string}
- function proxy witch accepts net object and string 'host:port'
Plugins