Asynchronously build a mapping of entries in hostRoot
to
application root paths and proxy ports. For each symlink, store the
symlink’s name and the real path of the application it points to.
For each directory, store the directory’s name and its full path.
For each file that contains a port number, store the file’s name and
the port. The mapping is passed as an object to the second argument
of callback
. If an error is raised, callback
is called with the
error as its first argument.
The mapping object will look something like this:
{
"basecamp": { "root": "/Volumes/37signals/basecamp" },
"launchpad": { "root": "/Volumes/37signals/launchpad" },
"37img": { "root": "/Volumes/37signals/portfolio" },
"couchdb": { "url": "http://localhost:5984" }
}
gatherHostConfigurations: (callback) ->
hosts = {}
mkdirp @hostRoot, (err) =>
return callback err if err
fs.readdir @hostRoot, (err, files) =>
return callback err if err
async.forEach files, (file, next) =>
root = path.join @hostRoot, file
name = file.toLowerCase()
rstat root, (err, stats, path) ->
if stats?.isDirectory()
hosts[name] = root: path
next()
else if stats?.isFile()
fs.readFile path, 'utf-8', (err, data) ->
return next() if err
data = data.trim()
if data.length < 10 and not isNaN(parseInt(data))
hosts[name] = {url: "http://localhost:#{parseInt(data)}"}
else if data.match("https?://")
hosts[name] = {url: data}
next()
else
next()
, (err) ->
callback err, hosts