diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-11 13:16:28 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-11 13:20:22 +0100 |
commit | 90152c56c532d0784836f37427026b56508d52ab (patch) | |
tree | fee4ac8a0ab37cc21e87a5000fb74edfc18eb095 | |
parent | 1363593f6432c417b998a745fef1ce3439dda4f8 (diff) |
Better file serving
-rwxr-xr-x | webserver.js | 7 |
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]!=".";}) |