var http = require('http')

function getHostOfRequest(req){
  var requestHost = req.headers.host;
  if(requestHost){
    var indexOfColon = requestHost.indexOf(':');
    if(indexOfColon>0){
      requestHost = requestHost.substr(0,requestHost.indexOf(':'));
    }
  }
  return requestHost;
}

// module.exports is a middleware
module.exports = function (redirects, port) {
  return http.createServer(function (req, res) {
    var requestHost = getHostOfRequest(req);
    var redirect = redirects[requestHost];
    
    //if the host is not found in the configuration, we default to the catch all
    if(!redirect){
      redirect = redirects['*'];
    }
    
    if(redirect){
      var url = redirect.host + req.url;

      res.statusCode = redirect.code;
      res.setHeader('Content-Type', 'text/plain');
      res.setHeader('Location', url);
      res.end('Redirecting to '+url);
    }else{
    	//their is no catch all, we will just show an error message
    	res.statusCode = 404;
        res.setHeader('Content-Type', 'text/plain');
        res.end('Host not found');
    }
    
  }).listen(port);
}

@@ -23,273 +23,9 @@
 tp')
-%0A%0Afunction getHostOfRequest(req)%7B%0A  var requestHost = req.headers.host;%0A  if(requestHost)%7B%0A    var indexOfColon = requestHost.indexOf(':');%0A    if(indexOfColon%3E0)%7B%0A      requestHost = requestHost.substr(0,requestHost.indexOf(':'));%0A    %7D%0A  %7D%0A  return requestHost;%0A%7D
+;
 %0A%0A//
@@ -177,29 +177,38 @@
 t = 
-getHostOfRequest(req)
+req.headers.host.split(':')%5B0%5D
 ;%0A  

simplified the code