// This code is far from finished, its a concept currently
// This is not going to be super advanced and it relies quite heavilly the awesome
// libary from nodejitsu, we are litrelly just coding a nice system around it
//
// We know about nginx and haproxy but the problem with them is that we really dont know 
// much about configuring them beyond basic settings, by building our own system
// we can do things like dynamic host addition without having to worry about how to configure that
// feel free to do pull requests if you can improve our code, we love open source stuff

// Licence is currently the mozila public licence, but am not 100% sure which licence is best
// was going to use GNU but something put me off it, if you want to change the licence make a
// pull request that makes the change and gives a good explanation as to why its a good licence

var packagejson = require('./package.json'),
    http = require('http'),
    httpProxy = require('http-proxy'),
    proxy = httpProxy.createProxyServer({});

var port = 3000;

// Proxy setup
var server = http.createServer(function(req, res) {
    //TODO: Logic to pick server

    // If running in test mode then use servers created in mocha instead of defined servers
    if(process.env.NODE_ENV !== 'test') {
        proxy.web(req, res, { target: 'http://10.0.6.5:80' });
    } else {
        proxy.web(req, res, { target: 'http://127.0.0.1:4000' });
    }
});

// Display console info
// but not for mocha test
if(process.env.NODE_ENV !== 'test') {
    console.log('');
    console.log('TrackProxy v'+packagejson.version);
    console.log('listening on port '+port);
    console.log('');
}
server.listen(port);
@@ -1032,17 +1032,17 @@
 rt = 300
-0
+1
 ;%0A%0A// Pr
@@ -1322,23 +1322,34 @@
 ://1
+27.
 0.0.
-6.5:8
+1:300
 0' %7D);
+        
 %0A   
@@ -1430,21 +1430,1268 @@
 ;%0A    %7D%0A
-
 %7D);%0A%0A
+%0A// 504 error handler%0A// TODO: Figure out a way to try another server instead of just displaying an error%0A// probably as simple as just doing proxy.web in this block, but need to be sure not to cause loops%0Aproxy.on('error', function (err, req, res) %7B%0A  res.writeHead(504, %7B%0A    'Content-Type': 'text/html'%0A  %7D);%0A%0A  res.end('%3Ch1%3EERROR 504 GATEWAY TIMEOUT%3C/h1%3E%3Chr%3E%3Cbr%3ENo servers can handle your request%3Cbr%3ETry again in 30 seconds, this error usually ocours if the is a high load on the website %3Cbr%3E%3Cbr%3E%3Ccode%3EDebug info%3Cbr%3E'+err+'%3Cbr%3Eserver removed to prevent a major disaster%3Cbr%3Ewill re-add if we get a heartbeat%3C/code%3E%3Cbr%3E%3Cbr%3E%3Ch4%3ETrackProxy%3C/h4%3E');%0A%7D);%0A%0A%0A// Display no servers error if the are no servers to pick from%0A// Would happen usually if all the servers are down and would be removed from the pool %0Afunction noserverfound(req, res) %7B%0A    res.writeHead(503, %7B%0A        'Content-Type': 'text/html'%0A    %7D);%0A    res.end('%3Ch1%3EERROR 503 SERVICE UNAVAILABLE%3C/h1%3E%3Chr%3E%3Cbr%3ENo servers can handle your request%3Cbr%3ETry again in 30 seconds, this error usually ocours if the is a high load on the website %3Cbr%3E%3Cbr%3E%3Ccode%3EDebug info%3Cbr%3ENo servers in proxy pool, no where to go%3Cbr%3Ewaiting for a backend server to be added%3C/code%3E%3Cbr%3E%3Cbr%3E%3Ch4%3ETrackProxy%3C/h4%3E');%0A%7D%0A%0A
 // Displ

Add error responses