mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
updating docs, almost there
This commit is contained in:
parent
b1eb13eb70
commit
6e651f420f
22
README.md
22
README.md
@ -27,10 +27,28 @@ Let's suppose you were running multiple http application servers, but you only w
|
||||
|
||||
### 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?
|
||||
|
||||
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
19
demo.js
@ -6,14 +6,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
sys = require('sys'),
|
||||
var sys = require('sys'),
|
||||
colors = require('colors')
|
||||
assert = require('assert'),
|
||||
http = require('http');
|
||||
|
||||
var httpProxy = require('./lib/node-http-proxy');
|
||||
var testServers = {};
|
||||
var httpProxy = require('./lib/node-http-proxy').httpProxy;
|
||||
|
||||
|
||||
// ascii art from http://github.com/marak/asciimo
|
||||
@ -27,20 +24,10 @@ var welcome = '\
|
||||
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
|
||||
http.createServer(function (req, res){
|
||||
var proxy = new httpProxy.httpProxy;
|
||||
var proxy = new httpProxy;
|
||||
proxy.init(req, res);
|
||||
sys.puts('proxying request to http://localhost:9000');
|
||||
proxy.proxyRequest('localhost', '9000', req, res);
|
||||
|
||||
@ -13,7 +13,7 @@ var vows = require('vows'),
|
||||
|
||||
require.paths.unshift(require('path').join(__dirname, '../lib/'));
|
||||
|
||||
var httpProxy = require('node-http-proxy');
|
||||
var httpProxy = require('node-http-proxy').httpProxy;
|
||||
var testServers = {};
|
||||
|
||||
//
|
||||
@ -89,7 +89,7 @@ vows.describe('node-proxy').addBatch({
|
||||
"When an incoming request is proxied to the helloNode server" : {
|
||||
"with no latency" : {
|
||||
topic: function () {
|
||||
var proxy = new httpProxy.httpProxy;
|
||||
var proxy = new httpProxy;
|
||||
startTest(proxy, 8082);
|
||||
proxy.emitter.addListener('end', this.callback);
|
||||
|
||||
@ -106,7 +106,7 @@ vows.describe('node-proxy').addBatch({
|
||||
},
|
||||
"with latency": {
|
||||
topic: function () {
|
||||
var proxy = new httpProxy.httpProxy;
|
||||
var proxy = new httpProxy;
|
||||
startTestWithLatency(proxy, 8083);
|
||||
proxy.emitter.addListener('end', this.callback);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user