Permalink
Browse files

show directory

  • Loading branch information...
kenu committed Nov 1, 2012
1 parent f747139 commit f89b78e92e7a4ce682035f280a2c1100c538db5c
Showing with 24 additions and 5 deletions.
  1. +21 −4 lib/locally.js
  2. +3 −1 package.json
View
@@ -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('<ul>');
+ if (uri != '/') {
+ res.write('<li><a href=\'../\'>../</a></li>');
+ }
+ for(var i in files) {
+ res.write('<li><a href='+files[i]+'>'+files[i]+'</a></li>');
+ }
+ res.write('</ul>');
+ res.end();
+ });
+ }
+ }
+ });
- res.statusCode = 301;
- res.setHeader('Location', req.url);
- res.end();
});
app.listen(program.port);
View
@@ -15,7 +15,9 @@
},
"dependencies": {
"commander": "1.0.x",
- "connect": "1.8.x"
+ "connect": "1.8.x",
+ "keypress": "x",
+ "colors": "x"
},
"devDependencies": {},
"optionalDependencies": {}

0 comments on commit f89b78e

Please sign in to comment.