Cache storefront images aggressively while keeping CSS revalidatable.

Split static asset mounts by type and centralize paths in storefrontAssetPaths so icon URLs stay aligned with the server.
This commit is contained in:
2026-09-07 14:06:44 +02:00
parent e6c21e58bb
commit 0dcffb394e
3 changed files with 28 additions and 5 deletions
@@ -0,0 +1,12 @@
import path from 'node:path';
export const storefrontImgUrlPrefix = '/shop/assets/img';
export const storefrontCssUrlPrefix = '/shop/assets/css';
export const getStorefrontPublicDir = (): string =>
path.join(__dirname, '..', 'modules', 'storefrontCore', 'public');
export const getStorefrontImgDir = (): string => path.join(getStorefrontPublicDir(), 'img');
export const getStorefrontCssDir = (): string => path.join(getStorefrontPublicDir(), 'css');
+3 -2
View File
@@ -1,6 +1,7 @@
import { storefrontImgUrlPrefix } from '../config/storefrontAssetPaths';
import { PaymentMethod } from '../modules/payment/types/PaymentMethod'; import { PaymentMethod } from '../modules/payment/types/PaymentMethod';
export const paymentMethodIconUrl: Record<PaymentMethod, string> = { export const paymentMethodIconUrl: Record<PaymentMethod, string> = {
[PaymentMethod.Xmr]: '/shop/assets/img/xmr.png', [PaymentMethod.Xmr]: `${storefrontImgUrlPrefix}/xmr.png`,
[PaymentMethod.Btc]: '/shop/assets/img/btc.png' [PaymentMethod.Btc]: `${storefrontImgUrlPrefix}/btc.png`
}; };
+13 -3
View File
@@ -5,6 +5,12 @@ import { ConfigService } from '@nestjs/config';
import cookieParser from 'cookie-parser'; import cookieParser from 'cookie-parser';
import hbs from 'hbs'; import hbs from 'hbs';
import path from 'node:path'; import path from 'node:path';
import {
getStorefrontCssDir,
getStorefrontImgDir,
storefrontCssUrlPrefix,
storefrontImgUrlPrefix
} from './config/storefrontAssetPaths';
import { getPublicUploadsDir, publicUploadsUrlPrefix } from './config/uploadPaths'; import { getPublicUploadsDir, publicUploadsUrlPrefix } from './config/uploadPaths';
import { AppModule } from './AppModule'; import { AppModule } from './AppModule';
import { registerStorefrontHelpers } from './modules/storefrontCore/utils/registerStorefrontHelpers'; import { registerStorefrontHelpers } from './modules/storefrontCore/utils/registerStorefrontHelpers';
@@ -26,10 +32,14 @@ async function bootstrap() {
immutable: true immutable: true
}); });
const storefrontPublicDir = path.join(__dirname, 'modules', 'storefrontCore', 'public'); app.useStaticAssets(getStorefrontImgDir(), {
prefix: storefrontImgUrlPrefix,
maxAge: '1y',
immutable: true
});
app.useStaticAssets(storefrontPublicDir, { app.useStaticAssets(getStorefrontCssDir(), {
prefix: '/shop/assets' prefix: storefrontCssUrlPrefix
}); });
app.use(cookieParser()); app.use(cookieParser());