From 0dcffb394ea9b3f7bf4592e5335c3508acdc9a6a Mon Sep 17 00:00:00 2001 From: nobswebdev Date: Mon, 7 Sep 2026 14:06:44 +0200 Subject: [PATCH] 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. --- backend/src/config/storefrontAssetPaths.ts | 12 ++++++++++++ backend/src/consts/paymentMethodIconUrl.ts | 5 +++-- backend/src/main.ts | 16 +++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 backend/src/config/storefrontAssetPaths.ts diff --git a/backend/src/config/storefrontAssetPaths.ts b/backend/src/config/storefrontAssetPaths.ts new file mode 100644 index 0000000..8135603 --- /dev/null +++ b/backend/src/config/storefrontAssetPaths.ts @@ -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'); diff --git a/backend/src/consts/paymentMethodIconUrl.ts b/backend/src/consts/paymentMethodIconUrl.ts index 1128fe1..5b775ab 100644 --- a/backend/src/consts/paymentMethodIconUrl.ts +++ b/backend/src/consts/paymentMethodIconUrl.ts @@ -1,6 +1,7 @@ +import { storefrontImgUrlPrefix } from '../config/storefrontAssetPaths'; import { PaymentMethod } from '../modules/payment/types/PaymentMethod'; export const paymentMethodIconUrl: Record = { - [PaymentMethod.Xmr]: '/shop/assets/img/xmr.png', - [PaymentMethod.Btc]: '/shop/assets/img/btc.png' + [PaymentMethod.Xmr]: `${storefrontImgUrlPrefix}/xmr.png`, + [PaymentMethod.Btc]: `${storefrontImgUrlPrefix}/btc.png` }; diff --git a/backend/src/main.ts b/backend/src/main.ts index 84afdc1..4f5f5ec 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -5,6 +5,12 @@ import { ConfigService } from '@nestjs/config'; import cookieParser from 'cookie-parser'; import hbs from 'hbs'; import path from 'node:path'; +import { + getStorefrontCssDir, + getStorefrontImgDir, + storefrontCssUrlPrefix, + storefrontImgUrlPrefix +} from './config/storefrontAssetPaths'; import { getPublicUploadsDir, publicUploadsUrlPrefix } from './config/uploadPaths'; import { AppModule } from './AppModule'; import { registerStorefrontHelpers } from './modules/storefrontCore/utils/registerStorefrontHelpers'; @@ -26,10 +32,14 @@ async function bootstrap() { immutable: true }); - const storefrontPublicDir = path.join(__dirname, 'modules', 'storefrontCore', 'public'); + app.useStaticAssets(getStorefrontImgDir(), { + prefix: storefrontImgUrlPrefix, + maxAge: '1y', + immutable: true + }); - app.useStaticAssets(storefrontPublicDir, { - prefix: '/shop/assets' + app.useStaticAssets(getStorefrontCssDir(), { + prefix: storefrontCssUrlPrefix }); app.use(cookieParser());