Skip to content

Commit

Permalink
Add edge cacheing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jan 21, 2023
1 parent d8008b4 commit f10230d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
12 changes: 8 additions & 4 deletions controllers/about.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = (req, res) => res.render('about.html', {
bodyClass: 'about',
pageTitle: 'About'
});
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'
})
};
16 changes: 10 additions & 6 deletions controllers/listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ module.exports = (req, res, next) => {
}

tor.listNodes(query)
.then(nodes => res.render('listing.html', {
pageTitle: req.query.s ? `Search: ${req.query.s}` : false,
title,
nodes,
numOfNodes: query.limit
}))
.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';
Expand Down
2 changes: 2 additions & 0 deletions controllers/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

1 comment on commit f10230d

@vercel
Copy link

@vercel vercel bot commented on f10230d Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

onionite-new – ./

onionite-new.vercel.app
onionite-new-lukechilds.vercel.app
onionite-new-git-master-lukechilds.vercel.app

Please sign in to comment.