diff --git a/services/cache/mecache/cache.js b/services/cache/mecache/cache.js index 435be2d5..d99b977a 100644 --- a/services/cache/mecache/cache.js +++ b/services/cache/mecache/cache.js @@ -41,7 +41,7 @@ let cache = () => { return (req, res, next) => { if(req.query.url) { if(mcache.size() > cacheMaxSize){ - console.debug("Max cache size reached!"+cacheMaxSize); + console.log("Max cache size reached!"+cacheMaxSize); clearCache(); } let key = '__express__' + req.query.url; @@ -129,33 +129,14 @@ app.get('/get', cache(), cors(), (req, res) => { }); -app.get('/get', cache(30), cors(), (req, res) => { - setTimeout(() => { - const url = (req.query) ? req.query.url : null; - if (!url) { - res.status(404).send(getResponse(404, "Not Found ")) //not found - } else { - request.get(url, function (err, response) { - // res.header("Access-Control-Allow-Origin", "http://localhost:3000"); - res.header("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length"); - res.header("Access-Control-Allow-Methods", "GET, OPTIONS"); - res.header("Access-Control-Allow-Methods", "GET, OPTIONS"); - res.header("Content-Type", "application/json"); - if (!response && err) { - res.status(500).send(getResponse(500, "An error occurred for " + url)) - } else { - res.status(response.status).send(response.body); - } - }) - } - }) -}); app.use((req, res) => { res.status(404).send(getResponse(404, "Not Found")); //not found }); app.listen((process.env.PORT) ? process.env.PORT : 3000, function () { - console.log(`Example app listening on port ${process.env.PORT}!`) + console.log(`Example app listening on port ${(process.env.PORT) ? process.env.PORT : 3000}!`) + //run the timer + resetAtMidnight(); }); function getResponse(code, message) { @@ -166,7 +147,7 @@ function getResponse(code, message) { } function clearCache(){ - console.debug("cache is cleared!"); + console.log("cache is cleared!"); mcache.clear(); entries.set(mcache.size()); } @@ -179,10 +160,8 @@ function checkForLongCachedRequests(url){ }); return long; } -//run the timer -resetAtMidnight(); function resetAtMidnight() { - console.debug("Run Reset timer"); + console.log("Run Reset timer"); var now = new Date(); var night = new Date( now.getFullYear(),