diff options
-rwxr-xr-x | webserver.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/webserver.js b/webserver.js index 62a1719..84864cd 100755 --- a/webserver.js +++ b/webserver.js @@ -52,8 +52,7 @@ for(i=0;i<module_list.length;i++){ function requestFile(req,res,path){ - var parsed=url.parse(req.url),basefname=parsed.pathname.slice(2).replace(/\/\.+[^\/]*\//g,"/"); - fname=cmn.rootdir+"/web_files"+basefname; + fname=cmn.rootdir+"/web_files"+path; console.log("Requesting file "+fname); if(!fs.existsSync(fname)){ res.send("That file does not exist."); @@ -70,15 +69,15 @@ function requestFile(req,res,path){ }); res.send( String(fs.readFileSync(cmn.rootdir+"/web_files/dirlisting.html")) - .replace("<!--DIRDIR-->",basefname) + .replace("<!--DIRDIR-->",path) .replace("[/*LISTINGLISTING*/]",JSON.stringify(items)) ); } else res.send("I don't recognise that file."); } -function makeUrlSafe(req){ - var parsed=url.parse(req.url),basefname=parsed.pathname.slice(2).replace(/\/\.+[^\/]*\//g,"/"); - return basefname; +function makeUrlSafe(req,sliceLength){ + var parsed=url.parse(req.url); + return parsed.pathname.slice(sliceLength).replace(/\/\.+[^\/]*\//g,"/"); } @@ -94,11 +93,11 @@ app.get("/",function(req,res){ app.get(["/f/univq","/f/univq/*"],cmn.authgen()); app.get("/f/*",function(req,res){ - requestFile(req,res,makeUrlSafe(req)); + requestFile(req,res,makeUrlSafe(req,2)); }); app.get("/.well-known/*",function(req,res){ - requestFile(req,res,"/well-known"+makeUrlSafe(req)); + requestFile(req,res,"/well-known"+makeUrlSafe(req,12)); }); ["o","k","rip","rip2"].forEach(function(target){ |