From 20c497ba846d30a33490810b92af29c99e99b57f Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 3 Oct 2023 00:35:11 +0200 Subject: [PATCH] feat: cache middleware --- server/cache.js | 9 +++++++++ server/main.js | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 server/cache.js diff --git a/server/cache.js b/server/cache.js new file mode 100644 index 0000000000..90799dbfad --- /dev/null +++ b/server/cache.js @@ -0,0 +1,9 @@ +/** + * @returns {import('express').RequestHandler} + */ +export function cache() { + return function (_req, res, next) { + res.setHeader('Cache-Control', 'max-age=3600, no-cache'); + next(); + } +} \ No newline at end of file diff --git a/server/main.js b/server/main.js index b73019a62c..792033f494 100644 --- a/server/main.js +++ b/server/main.js @@ -1,16 +1,14 @@ import express from 'express'; import compression from 'compression' +import { cache } from './cache.js'; import { sitemap } from './sitemap.js' import { handler } from '../build/handler.js'; async function main() { const app = express(); + app.use(cache()); app.use(compression()); app.use(await sitemap()); - app.use(function (_req, res, next) { - res.setHeader('Cache-Control', 'max-age=3600, no-cache'); - next(); - }); app.use(handler); app.listen(3000, () => { console.log('Listening on http://0.0.0.0:3000');