2025-02-22 23:42:20 +01:00
|
|
|
const expressStaticGzip = require('express-static-gzip');
|
2024-08-04 21:17:59 -04:00
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
const oneDayInSeconds = 24 * 60 * 60;
|
2024-08-04 21:17:59 -04:00
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
const sMaxAge = process.env.STATIC_CACHE_S_MAX_AGE || oneDayInSeconds;
|
|
|
|
|
const maxAge = process.env.STATIC_CACHE_MAX_AGE || oneDayInSeconds * 2;
|
2024-08-04 21:17:59 -04:00
|
|
|
|
|
|
|
|
const staticCache = (staticPath) =>
|
2025-02-22 23:42:20 +01:00
|
|
|
expressStaticGzip(staticPath, {
|
|
|
|
|
enableBrotli: false, // disable Brotli, only using gzip
|
|
|
|
|
orderPreference: ['gz'],
|
|
|
|
|
setHeaders: (res, _path) => {
|
|
|
|
|
if (process.env.NODE_ENV?.toLowerCase() === 'production') {
|
|
|
|
|
res.setHeader('Cache-Control', `public, max-age=${maxAge}, s-maxage=${sMaxAge}`);
|
2024-08-04 21:17:59 -04:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = staticCache;
|