Skip to content

Commit

Permalink
Added env HTTP_CACHE_MAX_AGE setting
Browse files Browse the repository at this point in the history
This env setting controls production http cache max age. Default value is '30d' when setting is not given. Max age can be given in many units like seconds(s), minutes(m), hours(h) and days(d).
  • Loading branch information
SanttuA committed Oct 9, 2023
1 parent 1488b1f commit 24ebfb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const isProduction = process.env.NODE_ENV === 'production';

const defaultPort = isProduction ? 8080 : 3000;
const port = process.env.PORT || defaultPort;
// max age can be given in many units like seconds(s), minutes(m), hours(h) and days(d)
const httpCacheMaxAge = process.env.HTTP_CACHE_MAX_AGE || '30d';

function getAssetHash(filePath) {
if (!isProduction) return '';
Expand Down Expand Up @@ -33,4 +35,5 @@ module.exports = {
matomoSiteId: process.env.MATOMO_SITE_ID,
port,
webpackStylesExtensions: ['css', 'scss'],
httpCacheMaxAge,
};
2 changes: 1 addition & 1 deletion server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (serverConfig.isProduction) {
app.use(compression());

// Serve the static assets. We can cache them as they include hashes.
app.use('/_assets', express.static(path.resolve(__dirname, '../dist'), { maxAge: '200d' }));
app.use('/_assets', express.static(path.resolve(__dirname, '../dist'), { maxAge: serverConfig.httpCacheMaxAge }));
} else {
const webpackConfig = require('../config/webpack.development');
const compiler = webpack(webpackConfig);
Expand Down

0 comments on commit 24ebfb8

Please sign in to comment.