Skip to content

Commit

Permalink
Merge pull request #8 from kenu/master
Browse files Browse the repository at this point in the history
directory listing
  • Loading branch information
rhiokim committed Nov 26, 2012
2 parents f747139 + f89b78e commit bdef837
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 21 additions & 4 deletions lib/locally.js
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -15,7 +15,9 @@
},
"dependencies": {
"commander": "1.0.x",
"connect": "1.8.x"
"connect": "1.8.x",
"keypress": "x",
"colors": "x"
},
"devDependencies": {},
"optionalDependencies": {}
Expand Down

0 comments on commit bdef837

Please sign in to comment.