diff --git a/app.js b/app.js index bb13651..2906f08 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,6 @@ // GDS: Global Data System global['gds'] = { debug: (process.env.NODE_ENV === 'debug') ? true : false, - cache: {}, cfg: require(__dirname+'/bin/config') }; global['__dirname'] = __dirname; diff --git a/bin/web/module.js b/bin/web/module.js index 95176ad..81f36e5 100644 --- a/bin/web/module.js +++ b/bin/web/module.js @@ -45,35 +45,21 @@ methods.start = () => { //static files app.use('/res', (req, res, next) => { - if(typeof global['gds'].cache.web == 'undefined') global['gds'].cache.web = {}; let dir = global['__dirname'] + '/res/web'; let joined_path = path.join(dir, /^[^?]+/.exec(req.url)[0]); - // path already cached; not exist - if(global['gds'].cache.web[joined_path] == false) { - res.status(404).end(); - global['logs'].info("[web] (404) path not found: "+joined_path); - // path already cached; exist - } else if(global['gds'].cache.web[joined_path] == true){ - let contentType = mime.contentType(path.extname(joined_path)); - res.setHeader('Content-Type', contentType); - fs.createReadStream(joined_path).pipe(res); - // check path - } else { - fs.exists(joined_path, (exists) => { - global['gds'].cache.web[joined_path] = exists; - if(exists) { - let contentType = mime.contentType(path.extname(joined_path)); - res.setHeader('Content-Type', contentType); + fs.exists(joined_path, (exists) => { + if(exists) { + let contentType = mime.contentType(path.extname(joined_path)); + res.setHeader('Content-Type', contentType); - fs.createReadStream(joined_path).pipe(res); - } else { - res.status(404).end(); - global['logs'].info("[web] (404) path not found: "+joined_path); - } - }); - } + fs.createReadStream(joined_path).pipe(res); + } else { + res.status(404).end(); + global['logs'].info("[web] (404) path not found: "+joined_path); + } + }); }); // BodyParser & CookieParser diff --git a/bin/web/routes/static.js b/bin/web/routes/static.js index e59090e..4ccff68 100644 --- a/bin/web/routes/static.js +++ b/bin/web/routes/static.js @@ -13,26 +13,6 @@ path = require('path'); var cfg = require(global['__dirname']+'/bin/config'); -// reduce IO file checks - save file state in cache -var fileCheck = (file) => { - if(typeof global['gds'].cache.web == 'undefined') global['gds'].cache.web = {}; - let dir = global['__dirname'] + '/bin/web/views'; - let path_j = path.join(dir, file.toLowerCase()); - if(typeof global['gds'].cache.web[path_j] == 'undefined') { - if(fs.existsSync(path_j+'.pug')) { - global['gds'].cache.web[path_j] = true; - } else { - global['gds'].cache.web[path_j] = false; - } - } - - if(global['gds'].cache.web[path_j] === true) { - return path_j; - } else { - return false; - } -}; - let getRoutes = async () => { let db = global['requireModule']('database'); await db.connect(); @@ -164,10 +144,10 @@ let getRoutes = async () => { } }); - if(fileCheck(req.path)) { - // query apps - apps = await db.getApps(); + let dir = global['__dirname'] + '/bin/web/views'; + let path_j = path.join(dir, req.path.toLowerCase()); + if(fs.existsSync(path_j+'.pug')) { return res.render(req.path.replace(/^\//, ''), { session: req.session, apps: apps.reply,