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', bodyClass: 'about',
pageTitle: 'About' pageTitle: 'About'
}); })
};

8
controllers/listing.js

@ -17,12 +17,16 @@ module.exports = (req, res, next) => {
} }
tor.listNodes(query) 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, pageTitle: req.query.s ? `Search: ${req.query.s}` : false,
title, title,
nodes, nodes,
numOfNodes: query.limit numOfNodes: query.limit
})) })
})
.catch(err => { .catch(err => {
if (err.statusCode === 400 && req.query.s) { if (err.statusCode === 400 && req.query.s) {
err.statusMessage = 'Bad Search Query'; err.statusMessage = 'Bad Search Query';

2
controllers/node.js

@ -15,6 +15,8 @@ module.exports = (req, res, next) => {
throw err; 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', { res.render('node.html', {
pageTitle: `${data[0].type}: ${data[0].nickname}`, pageTitle: `${data[0].type}: ${data[0].nickname}`,
node: data[0], node: data[0],

Loading…
Cancel
Save