summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-12-11 13:16:28 +0100
committertomsmeding <tom.smeding@gmail.com>2016-12-11 13:20:22 +0100
commit90152c56c532d0784836f37427026b56508d52ab (patch)
treefee4ac8a0ab37cc21e87a5000fb74edfc18eb095
parent1363593f6432c417b998a745fef1ce3439dda4f8 (diff)
Better file serving
-rwxr-xr-xwebserver.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/webserver.js b/webserver.js
index 04984a0..77283af 100755
--- a/webserver.js
+++ b/webserver.js
@@ -66,9 +66,12 @@ app.get("/f/*",function(req,res){
var parsed=url.parse(req.url),basefname=parsed.pathname.slice(2).replace(/\/\.+[^\/]*\//g,"/");
fname=cmn.rootdir+"/web_files"+basefname;
console.log("Requesting file "+fname);
+ if(!fs.existsSync(fname)){
+ res.send("That file does not exist.");
+ return;
+ }
var stats=fs.statSync(fname);
- if(!fs.existsSync(fname))res.send("That file does not exist.");
- else if(stats.isFile())res.sendFile(fname);
+ if(stats.isFile())res.sendFile(fname);
else if(stats.isDirectory()){
var items=fs.readdirSync(fname)
.filter(function(f){return f[0]!=".";})