connect = require 'connect'
vhost = require 'vhost'
DummySite = require './dummy_site'
fs = require 'fs'
noDelay = require '../../src/app.old'

module.exports.testConfigure = (cb)->
  app = connect();
  testConf = require './test_conf.json'

  for site of testConf.sites
    backendHost = testConf.sites[site].backend
    console.log "Creating vhost for #{backendHost}"

    app.use vhost(backendHost, DummySite(backendHost, testConf.sites[site].sitemap, testConf.port))
    delete testConf.sites[site].sitemap
    testConf.sites[site].backend += ":#{testConf.port}"

  fs.writeFileSync '/tmp/nodelay.json', JSON.stringify(testConf.sites)+"\n"

  app.listen testConf.port, ->
    # console.log "Backend server up and running"
    # noDelay '/tmp/nodelay.json', false, 3000, ->
    #   console.log "noDelay server up and running"
      cb()