feat: Static File Caching (#3455)

* add static file cache

* disable compression env variable
This commit is contained in:
matt burnett 2024-08-04 21:17:59 -04:00 committed by GitHub
parent 020c4a1a0e
commit e4ac42f034
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 99 additions and 5 deletions

View file

@ -0,0 +1,19 @@
const express = require('express');
const oneWeekInSeconds = 24 * 60 * 60 * 7;
const sMaxAge = process.env.STATIC_CACHE_S_MAX_AGE || oneWeekInSeconds;
const maxAge = process.env.STATIC_CACHE_MAX_AGE || oneWeekInSeconds * 4;
const staticCache = (staticPath) =>
express.static(staticPath, {
setHeaders: (res) => {
if (process.env.NODE_ENV.toLowerCase() !== 'production') {
return;
}
res.setHeader('Cache-Control', `public, max-age=${maxAge}, s-maxage=${sMaxAge}`);
},
});
module.exports = staticCache;