Browse Source

Add edge cacheing

master
Luke Childs 2 years ago
parent
commit
f10230dfc5
  1. 8
      controllers/about.js
  2. 8
      controllers/listing.js
  3. 2
      controllers/node.js

8
controllers/about.js

@ -1,4 +1,8 @@
module.exports = (req, res) => res.render('about.html', {
module.exports = (req, res) => {
const ONE_MONTH_IN_SECONDS = 60 * 60 * 24 * 30;
res.setHeader('Cache-Control', `s-maxage=${ONE_MONTH_IN_SECONDS}, stale-while-revalidate`);
res.render('about.html', {
bodyClass: 'about',
pageTitle: 'About'
});
})
};

8
controllers/listing.js

@ -17,12 +17,16 @@ module.exports = (req, res, next) => {
}
tor.listNodes(query)
.then(nodes => res.render('listing.html', {
.then(nodes => {
const ONE_HOUR_IN_SECONDS = 60 * 60;
res.setHeader('Cache-Control', `s-maxage=${ONE_HOUR_IN_SECONDS}, stale-while-revalidate`);
res.render('listing.html', {
pageTitle: req.query.s ? `Search: ${req.query.s}` : false,
title,
nodes,
numOfNodes: query.limit
}))
})
})
.catch(err => {
if (err.statusCode === 400 && req.query.s) {
err.statusMessage = 'Bad Search Query';

2
controllers/node.js

@ -15,6 +15,8 @@ module.exports = (req, res, next) => {
throw err;
}
const ONE_HOUR_IN_SECONDS = 60 * 60;
res.setHeader('Cache-Control', `s-maxage=${ONE_HOUR_IN_SECONDS}, stale-while-revalidate`);
res.render('node.html', {
pageTitle: `${data[0].type}: ${data[0].nickname}`,
node: data[0],

Loading…
Cancel
Save