feat: cache middleware

This commit is contained in:
Torsten Dittmann
2023-10-03 00:35:11 +02:00
parent 1e1d7607fa
commit 20c497ba84
2 changed files with 11 additions and 4 deletions

9
server/cache.js Normal file
View File

@@ -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();
}
}

View File

@@ -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');