summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwebserver.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/webserver.js b/webserver.js
index 84864cd..3e18b4d 100755
--- a/webserver.js
+++ b/webserver.js
@@ -7,6 +7,7 @@ var app=require("express")(),
url=require("url"),
fs=require("fs"),
util=require("util"),
+ node_path=require("path"),
bodyParser=require("body-parser"),
basicAuth=require("basic-auth");
@@ -61,12 +62,20 @@ function requestFile(req,res,path){
var stats=fs.statSync(fname);
if(stats.isFile())res.sendFile(fname);
else if(stats.isDirectory()){
- var items=fs.readdirSync(fname)
- .filter(function(f){return f[0]!=".";})
- .map(function(f){
- if(fs.statSync(fname+"/"+f).isDirectory())return f+"/";
- else return f;
- });
+ var items=fs
+ .readdirSync(fname)
+ .filter(function(f){return f[0]!=".";})
+ .map(function(f){
+ try {
+ if(fs.statSync(node_path.join(fname,f)).isDirectory())return f+"/";
+ else return f;
+ } catch(e){
+ return null;
+ }
+ })
+ .filter(function(f){
+ return f!==null;
+ });
res.send(
String(fs.readFileSync(cmn.rootdir+"/web_files/dirlisting.html"))
.replace("<!--DIRDIR-->",path)