 
   gatherApplicationRoots: (callback) ->
     roots = {}
-    fs.readdir @root, (err, files) =>
+    mkdirp @root, (err) =>
       return callback err if err
-      async.forEach files, (file, next) =>
-        path = join @root, file
-        fs.lstat path, (err, stats) ->
-          return callback err if err
-          if stats.isSymbolicLink()
-            fs.readlink path, (err, resolvedPath) ->
-              return callback err if err
-              roots[file] = resolvedPath
+      fs.readdir @root, (err, files) =>
+        return callback err if err
+        async.forEach files, (file, next) =>
+          root = path.join @root, file
+          fs.lstat root, (err, stats) ->
+            return callback err if err
+            if stats.isSymbolicLink()
+              fs.readlink root, (err, resolvedPath) ->
+                return callback err if err
+                roots[file] = resolvedPath
+                next()
+            else if stats.isDirectory()
+              roots[file] = root
               next()
-          else if stats.isDirectory()
-            roots[file] = path
-            next()
-          else
-            next()
-      , (err) ->
-        callback err, roots
+            else
+              next()
+        , (err) ->
+          callback err, roots

fs     = require "fs"
{join} = require "path"
async  = require "async"

getFilenamesForHost = (host) ->
  parts = host.split "."
  length = parts.length - 2
  for i in [0..length]
    parts.slice(i, length + 1).join "."

module.exports = class Configuration
  constructor: (options = {}) ->

    @dnsPort  = options.dnsPort  ? 20560
    @timeout  = options.timeout  ? 15 * 60 * 1000
    @domain   = options.domain   ? "test"
    @root     = options.root     ? path.join process.env.HOME, ".pow"

  findApplicationRootForHost: (host, callback) ->
    @gatherApplicationRoots (err, roots) =>
