added index support for file collections

This commit is contained in:
Ritchie
2012-03-31 17:28:11 -07:00
parent b2a05f88be
commit bc99dddd5c
2 changed files with 19 additions and 3 deletions

View File

@@ -68,8 +68,6 @@ var router = module.exports = function (req, res, next) {
};
return next();
}
// first look for a resource at the given path
// eg. `/todos` or `/my-files`

View File

@@ -28,7 +28,25 @@ module.exports = function (req, res, next, use) {
// list files
if(!filename) {
req.directory = true;
// return index.html if it exists
req.query._id = 'index.html';
storage.exec(req, function (err, body) {
if(!req.isRoot && body && body.file) {
res.header('Content-Type', mimeType);
res.header('Transfer-Encoding', 'chunked');
body.file.stream(true).pipe(res);
} else {
// just display the directory
delete req.query._id;
req.directory = true;
storage.exec(req, function (err, body) {
res.data = body;
next(err);
});
}
});
return;
}
// require a content type