From dcb4e0144703853aeabe8bd54e884eb286837706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20GOUIN?= Date: Thu, 20 Jun 2019 10:50:48 +0200 Subject: [PATCH] added readability check for fs.access --- src/app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index e51e450..3c645b2 100644 --- a/src/app.js +++ b/src/app.js @@ -44,9 +44,9 @@ module.exports = (config) => { }; const showError = (resPath, code, res) => { - const errorPath = path.join(config['data_dir'],config['home']['error']); - fs.access(errorPath, (err) => { - if(err) + const errorPath = path.join(config['data_dir'], config['home']['error']); + fs.access(errorPath, fs.constants.R_OK, (err) => { + if (err) res.sendStatus(code); else render(res, errorPath, {error: code, path: resPath}, code); @@ -55,8 +55,8 @@ module.exports = (config) => { app.get('/', (req, res) => { const homePath = `${config['data_dir']}/${config['home']['index']}`; - fs.access(homePath,(err)=>{ - if(err) + fs.access(homePath, fs.constants.R_OK, (err) => { + if (err) showError(req.path, 404, res); else render(res, homePath, {articles: articles});