Comparing version 1.3.0 to 1.3.1
// Requires | ||
var Q = require('q'); | ||
var _ = require('underscore'); | ||
var util = require('util'); | ||
var utils = require('./utils'); | ||
@@ -9,2 +11,7 @@ | ||
function ulog() { | ||
return util.log(_.toArray(arguments).join(' ')); | ||
} | ||
function GroupBalancer(config, resources) { | ||
@@ -72,4 +79,3 @@ // Bind methods to resource | ||
GroupBalancer.prototype.handle = function(req, res, proxy) { | ||
GroupBalancer.prototype.handle = function(req, res, _proxy) { | ||
var self = this; | ||
@@ -83,3 +89,3 @@ | ||
// Log | ||
console.log('Handle: ', req.headers.host+req.url); | ||
ulog('Handle:', req.headers.host+req.url); | ||
@@ -89,6 +95,17 @@ // Apply middleware | ||
.then(function() { | ||
console.log('Handled: ', backend.host+req.url); | ||
ulog('Handled:', backend.host+req.url); | ||
// Build proxy | ||
var proxy = new httpProxy.HttpProxy({ | ||
target: _.clone(backend) | ||
}); | ||
proxy.on('proxyError', function(err, req, res) { | ||
ulog('PROXY ERROR on ', backend.host+req.url); | ||
ulog(err); | ||
ulog(err.stack); | ||
}); | ||
// Handle (actual proxying) | ||
proxy.proxyRequest(req, res, _.clone(backend)); | ||
proxy.proxyRequest(req, res); | ||
@@ -104,4 +121,5 @@ // Resume request | ||
console.log('HTTP ERROR='); | ||
console.log(err.stack); | ||
ulog('HTTP ERROR='); | ||
ulog(err); | ||
ulog(err.stack); | ||
@@ -123,3 +141,3 @@ res.write(err.stack); | ||
// Log | ||
console.log('handleWs: ', req.headers.host+req.url); | ||
ulog('handleWs:', req.headers.host+req.url); | ||
@@ -129,3 +147,3 @@ // Apply middleware | ||
.then(function() { | ||
console.log('handledWs: ', backend.host+req.url); | ||
ulog('handledWs:', backend.host+req.url); | ||
@@ -137,2 +155,8 @@ // Build proxy | ||
proxy.on('webSocketProxyError', function(err, req, socket) { | ||
ulog('WS PROXY ERROR on ', backend.host+req.url); | ||
ulog(err); | ||
ulog(err.stack); | ||
}); | ||
// Actual proxying | ||
@@ -150,4 +174,5 @@ proxy.proxyWebSocketRequest(req, socket, head); | ||
console.log('WS ERROR ='); | ||
console.log(err.stack); | ||
ulog('WS ERROR ='); | ||
ulog(err); | ||
ulog(err.stack); | ||
@@ -182,6 +207,6 @@ socket.write('ERROR: Loadfire does not know how to handle that request'); | ||
connection.on('error', function (error) { | ||
console.log('TCP error from ' + getSocketInfo() + '; Error: ' + JSON.stringify(error)); | ||
ulog('TCP error from ' + getSocketInfo() + '; Error: ' + JSON.stringify(error)); | ||
}); | ||
connection.on('timeout', function () { | ||
console.log('TCP timeout from ' + getSocketInfo()); | ||
ulog('TCP timeout from ' + getSocketInfo()); | ||
connection.destroy(); | ||
@@ -188,0 +213,0 @@ }); |
{ | ||
"name" : "loadfire", | ||
"version" : "1.3.0", | ||
"version" : "1.3.1", | ||
"description" : "A clean and simple load balancer", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
19380
455