diff --git a/lib/cache.js b/lib/cache.js index e59f609..8393592 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -2,6 +2,12 @@ const needle = require('needle') const config = require('../config') +function isObject(obj) { + return typeof obj === 'object' && + !Array.isArray(obj) && + obj !== null +} + const getCached = () => { return new Promise((resolve, reject) => { const cached = { catalog: [] } @@ -21,7 +27,17 @@ const getCached = () => { } else { console.log('warning: could not load old addon catalog') } - resolve(cached) + + needle.get(`https://${config['netlify-domain']}/lastReached.json`, config.needle, (err, resp, body) => { + if (body && isObject(body) && Object.keys(body).length) { + console.log('loaded last reached data') + cached.lastReached = body + } else { + cached.lastReached = {} + console.log('warning: could not last reached data') + } + resolve(cached) + }) }) }) })