dirWatcher = require('./DirectoryWatchServer')
var path = require("path");
function getDirContentsOfRequest(req, thenDo) {
var baseDir = process.env.WORKSPACE_LK,
reqDir = path.join(baseDir, req.url);
dirWatcher.getWatchedFiles(dir, function(err, watchState) {
if (err) { thenDo(err, null); return; }
var files = Object.keys(watchState)
.filter(function(p) { return path.dirname(p) === dir; })
.reduce(function(fileMap, fileName) {
fileMap[fileName] = watchState[fileName]; }, {});
function isDirectory(stat) { return !!(stat.mode & 0040000); }
function convertFileStatsToDirInfos(fileStats, thenDo) {
var infos = Object.keys(fileStats).map(function(fn) {
isDirectory: isDirectory(fileStats[fn]),
lastModfied: fileStats[fn].mtime
function getDirInfosForRequest(req, thenDo) {
getDirContentsOfRequest(req, function(err, namesAndStats) {
if (err) { thenDo(err, null); return; }
convertFileStatsToDirInfos(namesAndStats, thenDo);
function findDirectoryListRoute(app, thenDo) {
var found = app.routes.get.reduce(function(found, ea) {
if (ea.callbacks.some(function(ea) { return !!ea.isLivelyDirectoryRoute; }))
return ea;
function removeExistingDirectoryListRoute(app, thenDo) {
findDirectoryListRoute(app, function(err, route) {
var i = app.routes.get.indexOf(route);