reproxy
v0.0.10
Published
Node.js reverse proxy.
Downloads
2
Maintainers
Readme
Reproxy
Reverse proxy for node.js applications.
Instalaltion
npm install reproxy
Access the the library like this:
var reproxy = require('reproxy');
Usage
Overview
To use reproxy you must implement your own reproxy adapter (or use existing ones). Reproxy doesn't come with any adapters, so this is will guide you for creating a simple one.
1. Creating a new adapter
var MyAdapter = Object.create(reproxy.Adapter);
1.1. Implement adapter's initialization method
MyArray.prototype.init = function() {
console.log("Adapter is being initialized.");
};
1.2. Implement adapter's fetch method
MyAdapter.prototype.fetch = function() {
return {
"app1.vcap.me" : { host: 'localhost', port: 3000 },
"app2.vcap.me" : { host: 'localhost', port: 3001 }
};
};
2. Running the proxy
// Creates the proxy using our adapter.
var proxy = new reproxy.Proxy(new MyAdapter());
2.1. Adding custom error handler
proxy.on('error', function(request, response, websocket) {
response.writeHead(500);
response.write("Cannot find routes for domain '" + request.headers.host + "'");
});
2.1. Adding transfer monitor
proxy.on('bandwidth', function(host, request, response) {
console.log('Proxy status for ' + host);
console.log(' Request: ' + request + ' bytes.');
console.log(' Response: ' + response + ' bytes.');
console.log('');
});
2.2. Run the proxy
proxy.run(80);