summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-02-01 20:13:28 +0100
committertomsmeding <tom.smeding@gmail.com>2018-02-01 20:13:28 +0100
commit8729493b181036c00db4f94777d38a4f2a8558bf (patch)
tree48fe2b682a26efc419a07d8cc5cf54a8e79bf8e9
parent667651cbaf61fa07049ddfa087922d22c97a97f6 (diff)
Show index.html by default in /f
-rwxr-xr-xwebserver.js16
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){