Skip to content

Commit

Permalink
[api] Corrected chain of argument passing
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Aug 2, 2010
1 parent 5d94ae2 commit da55777
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions demo.js
Expand Up @@ -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 = '\
Expand All @@ -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 );
Expand Down
14 changes: 7 additions & 7 deletions lib/node-http-proxy.js
Expand Up @@ -25,6 +25,7 @@
*/

var sys = require('sys'),
eyes = require('eyes'),
http = require('http'),
events = require('events');

Expand All @@ -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 = {
Expand All @@ -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){
Expand Down

0 comments on commit da55777

Please sign in to comment.