summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwebserver.js21
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)));
});