don't add upgrade handler if a custom handler is passed in

if a callback but no static proxy is defined and
no routes are provided then handlers.length is 1.
However the upgrade event is still automagically
attached in spite of having an explicit callback.
This commit is contained in:
Fabian Jakobs 2011-11-14 16:56:10 +01:00 committed by Charlie McConnell
parent 152d258ea0
commit d6ea3a425c

View File

@ -57,6 +57,7 @@ var HttpProxy = exports.HttpProxy = require('./node-http-proxy/http-proxy'
exports.createServer = function () {
var args = Array.prototype.slice.call(arguments),
handlers = [],
callback,
options = {},
message,
handler,
@ -77,7 +78,7 @@ exports.createServer = function () {
case 'string': host = arg; break;
case 'number': port = arg; break;
case 'object': options = arg || {}; break;
case 'function': handlers.push(arg); break;
case 'function': callback = arg; handlers.push(callback); break;
};
});
@ -180,7 +181,7 @@ exports.createServer = function () {
proxy.close();
});
if (handlers.length <= 1) {
if (!callback) {
//
// If an explicit callback has not been supplied then
// automagically proxy the request using the `HttpProxy`