From 49f6a0b8e2d3d4abfb35603545266a64a9703153 Mon Sep 17 00:00:00 2001 From: fenwick67 Date: Thu, 1 Aug 2019 22:15:33 -0400 Subject: [PATCH] add client-side caching --- index.js | 8 ++++++++ lib/convertv2.js | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ba33fbc..b9553e6 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,12 @@ app.use( }) ); +function doCache(res,durationSecs){ + res.set({ + "Cache-Control":"max-age="+durationSecs + }) +} + app.options('/api/feed',cors()); app.get('/api/feed',cors(),function(req,res){ @@ -79,6 +85,7 @@ app.get('/api/feed',cors(),function(req,res){ return res.send('Error fetching or parsing your feed.'); } res.status(200); + doCache(res,60*60) res.send(data); }); @@ -135,6 +142,7 @@ app.get('/apiv2/feed',cors(),function(req,res){ convertv2(opts).then((data)=>{ res.status(200); + doCache(res,60*60); res.send(data); }).catch((er)=>{ res.status(500); diff --git a/lib/convertv2.js b/lib/convertv2.js index 88a17a9..6388200 100644 --- a/lib/convertv2.js +++ b/lib/convertv2.js @@ -115,6 +115,10 @@ async function itemsForFeed(opts,user,feed) { // console.log(boostData[0]); boostData.forEach((boostToot)=>{ + + if (!boostToot.id){ + return;// case where it's a {} b/c the request failed or w/e + } // inject in-place into items @@ -127,7 +131,7 @@ async function itemsForFeed(opts,user,feed) { } if (index == -1){ - console.warn("warning: couldn't match boost to item: ",boostToot.id) + console.warn("warning: couldn't match boost to item: ",boostToot) return; }