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());