mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-10 04:22:18 +00:00
feat: cache middleware
This commit is contained in:
9
server/cache.js
Normal file
9
server/cache.js
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import compression from 'compression'
|
import compression from 'compression'
|
||||||
|
import { cache } from './cache.js';
|
||||||
import { sitemap } from './sitemap.js'
|
import { sitemap } from './sitemap.js'
|
||||||
import { handler } from '../build/handler.js';
|
import { handler } from '../build/handler.js';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
app.use(cache());
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
app.use(await sitemap());
|
app.use(await sitemap());
|
||||||
app.use(function (_req, res, next) {
|
|
||||||
res.setHeader('Cache-Control', 'max-age=3600, no-cache');
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
app.use(handler);
|
app.use(handler);
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log('Listening on http://0.0.0.0:3000');
|
console.log('Listening on http://0.0.0.0:3000');
|
||||||
|
|||||||
Reference in New Issue
Block a user