Files
ontime/apps/server/src/middleware/staticGZip.ts
T
Carlos Valente 1849b4d39f Deps migration (#1988)
* chore: migrate eslint to oxlint

* chore: migrate prettier to oxfmt

* chore: migrate typescript

* chore: toThrow should have a expected value

* chore: cast test value as Day

* chore: small title fix

* chore: mocks should be hoisted

* chore: incorrect async useage

* chore: test should be inside description

* chore: test sohuld include an expeced

* chore: oxfmt

---------

Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
2026-03-08 16:22:12 +01:00

28 lines
943 B
TypeScript

import { extname } from 'node:path';
import expressStaticGzip from 'express-static-gzip';
import { srcDir } from '../setup/index.js';
// serve static - react, in dev/test mode we fetch the React app from module
export const compressedStatic = expressStaticGzip(srcDir.clientDir, {
enableBrotli: true,
orderPreference: ['br'],
// when we build the client the file names contain a unique hash for the build
// this allows us to use the immutable tag
// as the contents of a build file will never change without also changing its name
// meaning that the client does not need to revalidate the contents with the server
serveStatic: {
etag: false,
lastModified: false,
immutable: true,
maxAge: '1y',
setHeaders: (res, file) => {
// make sure the HTML files are always revalidated
if (extname(file) === '.html') {
res.setHeader('Cache-Control', 'public, max-age=0');
}
},
},
});