diff --git a/server.js b/server.js index 51ca747..49a9fcf 100644 --- a/server.js +++ b/server.js @@ -34,6 +34,7 @@ app.get('/weather', (req, res) => { weather.doGetOpenWeather(req.query.ll) .then((d) => { + res.set('Cache-Control', 'public, max-age=1800'); res.send(d); }).catch((e) => { logger.error(e); @@ -54,6 +55,7 @@ app.get('/forecast', (req, res) => { weather.doGetFullForcast(req.query.ll) .then((d) => { + res.set('Cache-Control', 'public, max-age=1800'); res.send(d); }).catch((e) => { logger.error(e); @@ -73,6 +75,7 @@ app.get('/weatheralert', cache('15 minutes'), (req, res) => { // doGetDarkSkyWeather weather.doGetDarkSkyWeather(req.query.ll) .then((d) => { + res.set('Cache-Control', 'public, max-age=1800'); res.send(d); }).catch((e) => { logger.error(e); @@ -95,6 +98,7 @@ app.get('/fsexplore', cache('15 minutes'), (req, res) => { console.log('req.query',req.query); foursquare.doGetFourSquareExplore(ll, limit, section, query) .then((d) => { + res.set('Cache-Control', 'public, max-age=900'); res.send(d); }).catch((e) => { logger.error(e); @@ -109,10 +113,11 @@ app.get('/fsexplore', cache('15 minutes'), (req, res) => { } }); -app.get('/rightbyme', cache('15 minutes'), (req, res) => { +app.get('/rightbyme', cache('86400 seconds'), (req, res) => { if (req.query.hasOwnProperty('ll')) rightbyme.doGetRightByMe(req.query.ll) .then((d) => { + res.set('Cache-Control', 'public, max-age=86400'); res.send(d); }).catch((e) => { logger.error(e); @@ -130,6 +135,7 @@ app.get('/nearbydetail', cache('15 minutes'), (req, res) => { if (req.query.hasOwnProperty('id')) rightbyme.doGetMoreDetail(req.query.id) .then((d) => { + res.set('Cache-Control', 'public, max-age=900'); res.send(d); }).catch((e) => { logger.error(e); @@ -145,6 +151,7 @@ app.get('/nearbydetail', cache('15 minutes'), (req, res) => { app.get('/news', cache('15 minutes'), (req, res) => { euronews.getEuroNews().then((d) => { + res.set('Cache-Control', 'public, max-age=1800'); res.send(d); }).catch((e) => { if (e.message === '304:Not changed') { @@ -164,6 +171,7 @@ app.get('/article', cache('1 hour'), (req, res) => { euronews.getArticle(req.query.guid) .then((d) => { + res.set('Cache-Control', 'public, max-age=3600'); res.send(d); }).catch((e) => { logger.error(e); @@ -180,6 +188,7 @@ app.get('/article', cache('1 hour'), (req, res) => { app.get('/agenda', cache('15 minutes'), (req, res) => { agenda.doTodaysAgenda() .then((d) => { + res.set('Cache-Control', 'public, max-age=900'); res.send(d); }).catch((e) => { logger.error(e); @@ -193,6 +202,7 @@ app.get('/oldtraffic', cache('5 minutes'), (req, res) => { directions.getTraffic(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon) .then((d) => { + res.set('Cache-Control', 'public, max-age=900'); res.send(d); }).catch((e) => { logger.error(e); @@ -211,6 +221,7 @@ app.get('/incidents', cache('5 minutes'), (req, res) => { directions.getIncidents() .then((d) => { logger.debug(d); + res.set('Cache-Control', 'public, max-age=300'); res.send(d); }).catch((e) => { logger.error(e); @@ -225,6 +236,7 @@ app.get('/traffic', cache('5 minutes'), asyncMiddleware(async (req, res, next) = await directions.doGetEstDirectionsWithIncidents(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon).then((b) => { //logger.debug('b', b); + res.set('Cache-Control', 'public, max-age=300'); res.send(b); }).catch((e) => { logger.error(e); diff --git a/src/service-worker.js b/src/service-worker.js index 82b722d..a5456d1 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -const CACHE_VERSION = { 'version': '0.0.885' }; +const CACHE_VERSION = { 'version': '0.0.887' }; const PRECACHE = `jubileeData-${CACHE_VERSION.version}`; const RUNTIME = 'runtime'; @@ -124,7 +124,6 @@ self.addEventListener('fetch', event => { ); }*/ - console.log('Req', event.request.url); if (event.request.url.startsWith(self.location.origin)) { console.log('One of our requests..'); @@ -146,6 +145,8 @@ self.addEventListener('fetch', event => { event.respondWith( caches.open(RUNTIME).then(function(cache) { return cache.match(event.request).then(function (response) { + console.log('£', response); + return response || fetch(event.request).then(function(response) { cache.put(event.request, response.clone()); @@ -176,18 +177,3 @@ self.addEventListener('fetch', event => { ); } }); - -/* -self.addEventListener('fetch', function(event) { - event.respondWith( - caches.open('mysite-dynamic').then(function(cache) { - return cache.match(event.request).then(function (response) { - return response || fetch(event.request).then(function(response) { - cache.put(event.request, response.clone()); - return response; - }); - }); - }) - ); -}); - */