From 27af87300ffc989979e4d9742c0f6221b30a5039 Mon Sep 17 00:00:00 2001 From: Jemma Poffinbarger Date: Mon, 29 Jul 2024 15:03:00 -0500 Subject: [PATCH] fix: Added Cache-Control header to static files so cloudflare will cache them correctly --- src/services/juxt-web/routes/console/web.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/services/juxt-web/routes/console/web.js b/src/services/juxt-web/routes/console/web.js index 0ccfa18..6929c44 100644 --- a/src/services/juxt-web/routes/console/web.js +++ b/src/services/juxt-web/routes/console/web.js @@ -2,32 +2,40 @@ const express = require('express'); const router = express.Router(); const path = require('path'); +//* Keep the cache for 1 hour +const maxAge = 60 * 60; + router.get('/', function (req, res) { res.redirect('/titles/show'); }); router.get('/css/:filename', function (req, res) { res.set('Content-Type', 'text/css'); + res.set('Cache-Control', `public, max-age=${maxAge}`); res.sendFile('/css/' + req.params.filename, {root: path.join(__dirname, '../../../../webfiles/' + req.directory)}); }); router.get('/js/:filename', function (req, res) { res.set('Content-Type', 'application/javascript; charset=utf-8'); + res.set('Cache-Control', `public, max-age=${maxAge}`); res.sendFile('/js/' + req.params.filename, {root: path.join(__dirname, '../../../../webfiles/' + req.directory)}); }); router.get('/images/:filename', function (req, res) { res.set('Content-Type', 'image/png'); + res.set('Cache-Control', `public, max-age=${maxAge}`); res.sendFile('/images/' + req.params.filename, {root: path.join(__dirname, '../../../../webfiles/' + req.directory)}); }); router.get('/fonts/:filename', function (req, res) { res.set('Content-Type', 'font/woff'); + res.set('Cache-Control', `public, max-age=${maxAge}`); res.sendFile('/fonts/' + req.params.filename, {root: path.join(__dirname, '../../../../webfiles/' + req.directory)}); }); router.get('/favicon.ico', function (req, res) { res.set('Content-Type', 'image/x-icon'); + res.set('Cache-Control', `public, max-age=${maxAge}`); res.sendFile('/images/favicon.ico', {root: path.join(__dirname, '../../../../webfiles/' + req.directory)}); });