updating docs, almost there

This commit is contained in:
Marak Squires 2010-07-27 17:35:07 -04:00
parent b1eb13eb70
commit 6e651f420f
3 changed files with 27 additions and 22 deletions

View File

@ -27,10 +27,28 @@ Let's suppose you were running multiple http application servers, but you only w
### How to use node-http-proxy ### How to use node-http-proxy
#### usage 1:   creating a stand-alone proxy server ####    proxying requests using http.Server
#### usage 2:   proxying existing http.Server requests var sys = require('sys'),
colors = require('colors')
http = require('http');
var httpProxy = require('./lib/node-http-proxy').httpProxy;
http.createServer(function (req, res){
var proxy = new httpProxy;
proxy.init(req, res);
sys.puts('proxying request to http://localhost:9000');
proxy.proxyRequest('localhost', '9000', req, res);
}).listen(8000);
http.createServer(function (req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js) for further examples.
### Why doesn't node-http-proxy have more advanced features like x, y, or z? ### Why doesn't node-http-proxy have more advanced features like x, y, or z?
if you have a suggestion for a feature currently not supported, feel free to open a [support issue](https://github.com/nodejitsu/node-http-proxy/issues). node-http-proxy is designed to just proxy https request from one server to another, but we will be soon releasing many other complimentary projects that can be used in conjunction with node-http-proxy if you have a suggestion for a feature currently not supported, feel free to open a [support issue](https://github.com/nodejitsu/node-http-proxy/issues). node-http-proxy is designed to just proxy https request from one server to another, but we will be soon releasing many other complimentary projects that can be used in conjunction with node-http-proxy

19
demo.js
View File

@ -6,14 +6,11 @@
* *
*/ */
var vows = require('vows'), var sys = require('sys'),
sys = require('sys'),
colors = require('colors') colors = require('colors')
assert = require('assert'),
http = require('http'); http = require('http');
var httpProxy = require('./lib/node-http-proxy'); var httpProxy = require('./lib/node-http-proxy').httpProxy;
var testServers = {};
// ascii art from http://github.com/marak/asciimo // ascii art from http://github.com/marak/asciimo
@ -27,20 +24,10 @@ var welcome = '\
sys.puts(welcome.rainbow.bold); sys.puts(welcome.rainbow.bold);
// create regular http proxy server
httpProxy.createServer('localhost', 9000, function (req, res){
sys.puts('any requests going to 8002 will get proxied to 9000');
}).listen('localhost', 8002);
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
// create regular http proxy server // create regular http proxy server
http.createServer(function (req, res){ http.createServer(function (req, res){
var proxy = new httpProxy.httpProxy; var proxy = new httpProxy;
proxy.init(req, res); proxy.init(req, res);
sys.puts('proxying request to http://localhost:9000'); sys.puts('proxying request to http://localhost:9000');
proxy.proxyRequest('localhost', '9000', req, res); proxy.proxyRequest('localhost', '9000', req, res);

View File

@ -13,7 +13,7 @@ var vows = require('vows'),
require.paths.unshift(require('path').join(__dirname, '../lib/')); require.paths.unshift(require('path').join(__dirname, '../lib/'));
var httpProxy = require('node-http-proxy'); var httpProxy = require('node-http-proxy').httpProxy;
var testServers = {}; var testServers = {};
// //
@ -89,7 +89,7 @@ vows.describe('node-proxy').addBatch({
"When an incoming request is proxied to the helloNode server" : { "When an incoming request is proxied to the helloNode server" : {
"with no latency" : { "with no latency" : {
topic: function () { topic: function () {
var proxy = new httpProxy.httpProxy; var proxy = new httpProxy;
startTest(proxy, 8082); startTest(proxy, 8082);
proxy.emitter.addListener('end', this.callback); proxy.emitter.addListener('end', this.callback);
@ -106,7 +106,7 @@ vows.describe('node-proxy').addBatch({
}, },
"with latency": { "with latency": {
topic: function () { topic: function () {
var proxy = new httpProxy.httpProxy; var proxy = new httpProxy;
startTestWithLatency(proxy, 8083); startTestWithLatency(proxy, 8083);
proxy.emitter.addListener('end', this.callback); proxy.emitter.addListener('end', this.callback);