From bc99dddd5cb52fa7bf60b25ac5f6749c6a17fe71 Mon Sep 17 00:00:00 2001 From: Ritchie Date: Sat, 31 Mar 2012 17:28:11 -0700 Subject: [PATCH] added index support for file collections --- lib/router.js | 2 -- lib/types/static.js | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/router.js b/lib/router.js index 58181a1..15d0203 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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` diff --git a/lib/types/static.js b/lib/types/static.js index 9cafe5d..cc82a96 100644 --- a/lib/types/static.js +++ b/lib/types/static.js @@ -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