add client-side caching
This commit is contained in:
parent
3b682a12f4
commit
49f6a0b8e2
8
index.js
8
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.options('/api/feed',cors());
|
||||||
app.get('/api/feed',cors(),function(req,res){
|
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.');
|
return res.send('Error fetching or parsing your feed.');
|
||||||
}
|
}
|
||||||
res.status(200);
|
res.status(200);
|
||||||
|
doCache(res,60*60)
|
||||||
res.send(data);
|
res.send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -135,6 +142,7 @@ app.get('/apiv2/feed',cors(),function(req,res){
|
||||||
|
|
||||||
convertv2(opts).then((data)=>{
|
convertv2(opts).then((data)=>{
|
||||||
res.status(200);
|
res.status(200);
|
||||||
|
doCache(res,60*60);
|
||||||
res.send(data);
|
res.send(data);
|
||||||
}).catch((er)=>{
|
}).catch((er)=>{
|
||||||
res.status(500);
|
res.status(500);
|
||||||
|
|
|
@ -116,6 +116,10 @@ async function itemsForFeed(opts,user,feed) {
|
||||||
|
|
||||||
boostData.forEach((boostToot)=>{
|
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
|
// inject in-place into items
|
||||||
|
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
@ -127,7 +131,7 @@ async function itemsForFeed(opts,user,feed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == -1){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue