From da55777a92d100a5ddb7a8267e56ba26bd8c2270 Mon Sep 17 00:00:00 2001 From: indexzero Date: Sun, 1 Aug 2010 23:00:31 -0400 Subject: [PATCH] [api] Corrected chain of argument passing --- demo.js | 6 +++--- lib/node-http-proxy.js | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/demo.js b/demo.js index 8b5297e..2be729b 100644 --- a/demo.js +++ b/demo.js @@ -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 ); diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 640fee0..5b831f9 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -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){