Commit b1eb13eb authored by Marak Squires's avatar Marak Squires

added createServer but hated it, gonna remove

parent c4b7c0d8
......@@ -14,14 +14,23 @@
- written entirely in javascript
- easy to use api
### Todo
- add ability to black list ip addresses
### When to use node-http-proxy
Let's suppose you were running multiple http application servers, but you only wanted to expose one machine to the internet. You could setup node-http-proxy on that one machine and then reverse-proxy the incoming http requests to locally running services which were not exposed to the outside network.
### Installing node-http-proxy
<pre>
npm install http-proxy
</pre>
### How to use node-http-proxy
#### usage 1:&nbsp;&nbsp;&nbsp;creating a stand-alone proxy server
#### usage 2:&nbsp;&nbsp;&nbsp;proxying existing http.Server requests
### 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
\ No newline at end of file
/*
* node-proxy-test.js: Tests for node-proxy. Reverse proxy for node.js
*
* (C) 2010 Charlie Robbins
* (C) 2010 Charlie Robbins, Marak Squires
* MIT LICENSE
*
*/
......@@ -12,7 +12,7 @@ var vows = require('vows'),
assert = require('assert'),
http = require('http');
var HttpProxy = require('./lib/node-http-proxy').HttpProxy;
var httpProxy = require('./lib/node-http-proxy');
var testServers = {};
......@@ -26,17 +26,30 @@ var welcome = '\
# # # # # # # # #### # # # \n';
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);
var proxy = new httpProxy.httpProxy;
proxy.init(req, res);
sys.puts('proxying request to http://localhost:9000');
proxy.proxyRequest('localhost', '9000', req, res);
}).listen(8000);
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
// http proxy server with latency
http.createServer(function (req, res){
var proxy = new (HttpProxy);
var proxy = new (httpProxy);
proxy.init(req, res);
setTimeout(function(){
proxy.proxyRequest('localhost', '9000', req, res);
......@@ -47,9 +60,7 @@ sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '
// create regular http server
http.createServer(function (req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('foo');
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
sys.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
//sys.puts('to test the proxy server, request http://localhost:8080/ in your browser.');
//sys.puts('your request will proxy to the server running on port 8081');
\ No newline at end of file
......@@ -10,7 +10,7 @@ var sys = require('sys'),
http = require('http'),
events = require('events');
exports.HttpProxy = function () {
exports.httpProxy = function () {
var self = this;
this.emitter = new(events.EventEmitter);
......@@ -21,16 +21,16 @@ exports.HttpProxy = function () {
}
};
exports.HttpProxy.prototype = {
toArray: function (obj){
var len = obj.length,
arr = new Array(len);
for (var i = 0; i < len; ++i) {
arr[i] = obj[i];
}
return arr;
},
exports.createServer = function(callback){
sys.puts('httpProxy.createServer');
this.listen = function(host, port){
sys.puts(host + port);
};
return this;
};
exports.httpProxy.prototype = {
init: function (req, res) {
this.events = [];
var self = this;
......@@ -107,5 +107,13 @@ exports.HttpProxy.prototype = {
for (var i = 0, len = this.events.length; i < len; ++i) {
req.emit.apply(req, this.events[i]);
}
},
toArray: function (obj){
var len = obj.length,
arr = new Array(len);
for (var i = 0; i < len; ++i) {
arr[i] = obj[i];
}
return arr;
}
};
......@@ -13,7 +13,7 @@ var vows = require('vows'),
require.paths.unshift(require('path').join(__dirname, '../lib/'));
var HttpProxy = require('node-http-proxy').HttpProxy;
var httpProxy = require('node-http-proxy');
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);
var proxy = new httpProxy.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);
var proxy = new httpProxy.httpProxy;
startTestWithLatency(proxy, 8083);
proxy.emitter.addListener('end', this.callback);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment