From 6f4adbfc4f2e87ae233d56777db0b11235d76057 Mon Sep 17 00:00:00 2001 From: Joe Biellik Date: Thu, 2 Jul 2020 20:11:37 +0100 Subject: [PATCH] Improve caching --- router.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/router.js b/router.js index f8f3430..8fed064 100644 --- a/router.js +++ b/router.js @@ -1,10 +1,12 @@ const router = require('koa-router')(); +const conditional = require('koa-conditional-get')(); +const etag = require('koa-etag')(); const config = require('config'); const pastes = require('./controllers/pastes'); router - .get('/', async (ctx) => { - ctx.set('Cache-Control', 'no-cache'); + .get('/', conditional, etag, async (ctx) => { + ctx.set('Cache-Control', 'public'); await ctx.render('index', { pretty: config.prettyHtml, @@ -15,6 +17,6 @@ router }); }) .post('/', pastes.create) - .get('/:id', require('koa-conditional-get')(), require('koa-etag')(), pastes.view); + .get('/:id', conditional, etag, pastes.view); module.exports = router;