diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index e1c95f1..dd2279f 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -166,7 +166,7 @@ exports.createServer = function () { switch (typeof arg) { case 'string': host = arg; break; case 'number': port = arg; break; - case 'function': middleware.push(arg); break; + case 'function': middleware.push(handler = callback = arg); break; case 'object': options = arg; break; }; }); @@ -203,11 +203,15 @@ exports.createServer = function () { } } - if (middleware.length) { + if (middleware.length /*> 1*/) { //handler = callback = middleware.shift() //else if (middleware.length) handler = callback = stack(middleware, proxy); } + else if (middleware.length) { //do not use middleware code if it's not needed. + var h = middleware[0] + handler = callback = function (req,res) { h(req,res,proxy) }; + } if (!handler) { //