     return (req, res, next) ->
       req.url = "#{options.hostPath}#{req.url}"
       proxy.proxyRequest(req, res, options)
+
+  patchServerResponseForRedirects: (port, config) ->
+      writeHead = http.ServerResponse.prototype.writeHead
+      http.ServerResponse.prototype.writeHead = ->
+        @.emit('header') if (!@._emittedHeader)
+        @._emittedHeader = true
+        [ status, head ] = arguments
+        if status in [301,302]
+          oldLocation = "://#{config.host}:#{config.port}"
+          newLocation = "://#{config.host}:#{port}"
+          head.location = head.location.replace(oldLocation,newLocation)
+        return writeHead.apply(this, arguments)
 
   startTestacular: (targets = [], singleRun = true) ->
     # use custom testacular config file provided by user

    bestMatch.url

module.exports = Hem

     process.exit(1)
    # setup packages from options/slug
    @packages = (@createPackage(name, config) for name, config of @options.packages)
    # allow overrides
    @options.server.port = argv.port if argv.port
    @options.server.host or= ""

  server: ->
    # create app
