diff options
-rwxr-xr-x | webserver.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/webserver.js b/webserver.js index 1d618cc..549aebd 100755 --- a/webserver.js +++ b/webserver.js @@ -76,7 +76,7 @@ for(i=0;i<module_list.length;i++){ } -function requestFile(req,res,path){ +function requestFile(req,res,listdirs,path){ fname=cmn.rootdir+"/web_files"+path; console.log("Requesting file "+fname); if(!fs.existsSync(fname)){ @@ -86,7 +86,7 @@ function requestFile(req,res,path){ var stats=fs.statSync(fname); if(stats.isFile()){ res.sendFile(fname); - } else if(req.authuser!=null&&stats.isDirectory()){ + } else if(stats.isDirectory()&&listdirs){ var items=fs .readdirSync(fname) .filter(function(f){return f[0]!=".";}) @@ -103,9 +103,11 @@ function requestFile(req,res,path){ }); res.send( String(fs.readFileSync(cmn.rootdir+"/web_files/dirlisting.html")) - .replace("<!--DIRDIR-->",path) - .replace("[/*LISTINGLISTING*/]",JSON.stringify(items)) + .replace("<!--DIRDIR-->",path) + .replace("[/*LISTINGLISTING*/]",JSON.stringify(items)) ); + } else if(stats.isDirectory()&&fs.readdirSync(fname).indexOf("index.html")!=-1){ + res.sendFile(node_path.join(fname,"index.html")); } else { res.status(404).send("That file does not exist."); return; @@ -132,16 +134,16 @@ app.get("/",function(req,res){ app.get(["/f/univq","/f/univq/*"],cmn.authgen()); app.get(["/f","/f/*"],function(req,res){ - requestFile(req,res,unescape(makeUrlSafe(req,2))); + requestFile(req,res,false,unescape(makeUrlSafe(req,2))); }); app.get(["/ff","/ff/*"],cmn.authgen()); app.get(["/ff","/ff/*"],function(req,res){ - requestFile(req,res,unescape(makeUrlSafe(req,3))); + requestFile(req,res,true,unescape(makeUrlSafe(req,3))); }); app.get("/.well-known/*",function(req,res){ - requestFile(req,res,"/well-known"+unescape(makeUrlSafe(req,12))); + requestFile(req,res,false,"/well-known"+unescape(makeUrlSafe(req,12))); }); app.get("/google*.html",function(req,res){ |