2024-08-04 21:17:59 -04:00
|
|
|
const express = require('express');
|
|
|
|
|
|
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) =>
|
|
|
|
|
express.static(staticPath, {
|
|
|
|
|
setHeaders: (res) => {
|
2024-08-20 07:32:30 -04:00
|
|
|
if (process.env.NODE_ENV?.toLowerCase() !== 'production') {
|
2024-08-04 21:17:59 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.setHeader('Cache-Control', `public, max-age=${maxAge}, s-maxage=${sMaxAge}`);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = staticCache;
|