Skip to content

Commit da55777

Browse files
committed
[api] Corrected chain of argument passing
1 parent 5d94ae2 commit da55777

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

demo.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var sys = require('sys'),
2828
colors = require('colors')
2929
http = require('http'),
30-
httpProxy = require('http-proxy').HttpProxy;
30+
httpProxy = require('./lib/node-http-proxy');
3131

3232
// ascii art from http://github.com/marak/asciimo
3333
var welcome = '\
@@ -40,13 +40,13 @@ var welcome = '\
4040
sys.puts(welcome.rainbow.bold);
4141

4242
// create regular http proxy server
43-
httpProxy.createServer('localhost', '9000').listen(8000);
43+
httpProxy.createServer('localhost', 9000).listen(8000);
4444
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
4545

4646
// http proxy server with latency
4747
httpProxy.createServer(function (req, res, proxy){
4848
setTimeout(function(){
49-
proxy.proxyRequest('localhost', '9000', req, res);
49+
proxy.proxyRequest('localhost', 9000, req, res);
5050
}, 200)
5151
}).listen(8001);
5252
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with latency'.magenta.underline );

lib/node-http-proxy.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
var sys = require('sys'),
28+
eyes = require('eyes'),
2829
http = require('http'),
2930
events = require('events');
3031

@@ -37,7 +38,7 @@ exports.HttpProxy = function () {
3738
exports.createServer = function () {
3839
// Initialize the nodeProxy to start proxying requests
3940
var proxy = new (exports.HttpProxy);
40-
return proxy.createServer(arguments);
41+
return proxy.createServer.apply(proxy, arguments);
4142
};
4243

4344
exports.HttpProxy.prototype = {
@@ -51,18 +52,17 @@ exports.HttpProxy.prototype = {
5152
},
5253

5354
createServer: function () {
54-
var args = Array.prototype.slice.call(arguments),
55-
self = this,
55+
var self = this,
5656
server,
5757
port,
5858
callback;
5959

60-
if (typeof(args[0]) === "function") {
61-
callback = args[0];
60+
if (typeof(arguments[0]) === "function") {
61+
callback = arguments[0];
6262
}
6363
else {
64-
server = args[0];
65-
port = args[1];
64+
server = arguments[0];
65+
port = arguments[1];
6666
}
6767

6868
var proxyServer = http.createServer(function (req, res){

0 commit comments

Comments
 (0)