From f89b78e92e7a4ce682035f280a2c1100c538db5c Mon Sep 17 00:00:00 2001 From: kenu Date: Fri, 2 Nov 2012 01:50:39 +0900 Subject: [PATCH] show directory --- lib/locally.js | 25 +++++++++++++++++++++---- package.json | 4 +++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/locally.js b/lib/locally.js index 2dc42a4..a0817c1 100644 --- a/lib/locally.js +++ b/lib/locally.js @@ -96,15 +96,32 @@ function createServer() { } app.use(function(req, res, next) { - var fstream, file; if('GET' != req.method) { return next(); } + + fs.readFile(process.cwd(), function(err){ + if (err) { + if(err.errno === 28){ + var uri = require('url').parse(req.url).pathname; + var path = process.cwd() + uri; + fs.readdir(path, function(err1, files){ + res.writeHead(200, {"Content-Type": "text/html"}); + res.write(''); + res.end(); + }); + } + } + }); - res.statusCode = 301; - res.setHeader('Location', req.url); - res.end(); }); app.listen(program.port); diff --git a/package.json b/package.json index f5c06ea..b141681 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ }, "dependencies": { "commander": "1.0.x", - "connect": "1.8.x" + "connect": "1.8.x", + "keypress": "x", + "colors": "x" }, "devDependencies": {}, "optionalDependencies": {}