Commit da55777a authored by indexzero's avatar indexzero

[api] Corrected chain of argument passing

parent 5d94ae27
......@@ -27,7 +27,7 @@
var sys = require('sys'),
colors = require('colors')
http = require('http'),
httpProxy = require('http-proxy').HttpProxy;
httpProxy = require('./lib/node-http-proxy');
// ascii art from http://github.com/marak/asciimo
var welcome = '\
......@@ -40,13 +40,13 @@ var welcome = '\
sys.puts(welcome.rainbow.bold);
// create regular http proxy server
httpProxy.createServer('localhost', '9000').listen(8000);
httpProxy.createServer('localhost', 9000).listen(8000);
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
// http proxy server with latency
httpProxy.createServer(function (req, res, proxy){
setTimeout(function(){
proxy.proxyRequest('localhost', '9000', req, res);
proxy.proxyRequest('localhost', 9000, req, res);
}, 200)
}).listen(8001);
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with latency'.magenta.underline );
......
......@@ -25,6 +25,7 @@
*/
var sys = require('sys'),
eyes = require('eyes'),
http = require('http'),
events = require('events');
......@@ -37,7 +38,7 @@ exports.HttpProxy = function () {
exports.createServer = function () {
// Initialize the nodeProxy to start proxying requests
var proxy = new (exports.HttpProxy);
return proxy.createServer(arguments);
return proxy.createServer.apply(proxy, arguments);
};
exports.HttpProxy.prototype = {
......@@ -51,18 +52,17 @@ exports.HttpProxy.prototype = {
},
createServer: function () {
var args = Array.prototype.slice.call(arguments),
self = this,
var self = this,
server,
port,
callback;
if (typeof(args[0]) === "function") {
callback = args[0];
if (typeof(arguments[0]) === "function") {
callback = arguments[0];
}
else {
server = args[0];
port = args[1];
server = arguments[0];
port = arguments[1];
}
var proxyServer = http.createServer(function (req, res){
......
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