diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-09-06 19:21:31 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-09-06 19:21:31 +0200 |
commit | b3e906437937c463244880e3c374e38f9b60a19c (patch) | |
tree | 66bd2ef9dbd01723ec313641eac1dbab91201655 | |
parent | ba0419b8114584a1ed5b9183d38f8917b21805a5 (diff) |
Better treatment of /f vs /ff
-rwxr-xr-x | webserver.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/webserver.js b/webserver.js index d20384f..a190a4c 100755 --- a/webserver.js +++ b/webserver.js @@ -60,8 +60,9 @@ function requestFile(req,res,path){ return; } var stats=fs.statSync(fname); - if(stats.isFile())res.sendFile(fname); - else if(stats.isDirectory()){ + if(stats.isFile()){ + res.sendFile(fname); + } else if(req.authuser!=null&&stats.isDirectory()){ var items=fs .readdirSync(fname) .filter(function(f){return f[0]!=".";}) @@ -81,12 +82,17 @@ function requestFile(req,res,path){ .replace("<!--DIRDIR-->",path) .replace("[/*LISTINGLISTING*/]",JSON.stringify(items)) ); - } else res.send("I don't recognise that file."); + } else { + res.send("That file does not exist."); + return; + } } function makeUrlSafe(req,sliceLength){ var parsed=url.parse(req.url); - return parsed.pathname.slice(sliceLength).replace(/\/\.+[^\/]*\//g,"/"); + var part=parsed.pathname.slice(sliceLength); + if(part=="")return "/"; + return part.replace(/\/\.+[^\/]*\//g,"/"); } @@ -101,10 +107,15 @@ app.get("/",function(req,res){ app.get(["/f/univq","/f/univq/*"],cmn.authgen()); -app.get("/f/*",function(req,res){ +app.get(["/f","/f/*"],function(req,res){ requestFile(req,res,unescape(makeUrlSafe(req,2))); }); +app.get(["/ff","/ff/*"],cmn.authgen()); +app.get(["/ff","/ff/*"],function(req,res){ + requestFile(req,res,unescape(makeUrlSafe(req,3))); +}); + app.get("/.well-known/*",function(req,res){ requestFile(req,res,"/well-known"+unescape(makeUrlSafe(req,12))); }); |