Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

directory listing #8

Merged
merged 1 commit into from

2 participants

@kenu

안녕하세요.
디렉토리 보기 기능이 필요해서 추가했습니다.

덕분에 잘 사용하고 있습니다.
감사합니다.

@rhiokim rhiokim merged commit bdef837 into from
@rhiokim
Owner

@kenu 정말 필요하고 유용한 기능이네요. 감사합니다. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2012
  1. @kenu

    show directory

    kenu authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 5 deletions.
  1. +21 −4 lib/locally.js
  2. +3 −1 package.json
View
25 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('<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
4 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": {}
Something went wrong with that request. Please try again.