diff --git a/packages/storefront/astro.config.mjs b/packages/storefront/astro.config.mjs index d588d630d..be9e091e8 100644 --- a/packages/storefront/astro.config.mjs +++ b/packages/storefront/astro.config.mjs @@ -22,6 +22,7 @@ const deployRand = process.env.DEPLOY_RAND || '_'; const isLibDev = !(relativePath(__dirname, process.cwd())); const { + storeId, lang, domain, primaryColor, @@ -36,9 +37,9 @@ const getIconUrl = (size) => { const _vitePWAOptions = { manifest: { name: settings.name || 'My Shop', - short_name: settings.short_name || settings.name || 'MyShop', + short_name: settings.shortName || settings.name || 'MyShop', description: settings.description || 'My PWA Shop', - background_color: settings.bg_color || '#f5f6fa', + background_color: settings.bgColor || '#f5f6fa', theme_color: primaryColor, crossorigin: 'use-credentials', icons: [{ @@ -216,6 +217,12 @@ const genAstroConfig = ({ serviceEntryPoint: '@astrojs/image/sharp', })); } + let assetsPrefix; + if (!isSSG) { + assetsPrefix = storeId === 1011 && domain === 'demo.ecomplus.app' + ? 'https://s2-demo.b-cdn.net' + : settings.assetsPrefix; + } return { experimental: { viewTransitions: true, @@ -229,7 +236,9 @@ const genAstroConfig = ({ site, compressHTML: isToServerless, build: { + assetsPrefix, inlineStylesheets: 'never', + ...settings.build, }, vite: { plugins: [ diff --git a/packages/storefront/src/lib/ssr-context.ts b/packages/storefront/src/lib/ssr-context.ts index e83c54faa..81e413ab1 100644 --- a/packages/storefront/src/lib/ssr-context.ts +++ b/packages/storefront/src/lib/ssr-context.ts @@ -14,8 +14,8 @@ export type StorefrontConfig = { currency: BaseConfig['currency'], currencySymbol: BaseConfig['currencySymbol'], domain: SettingsContent['domain'], - primaryColor: SettingsContent['primary_color'], - secondaryColor: SettingsContent['secondary_color'], + primaryColor: SettingsContent['primaryColor'], + secondaryColor: SettingsContent['secondaryColor'], settings: SettingsContent, getContent: ContentGetter, }; @@ -179,6 +179,13 @@ const loadRouteContext = async (Astro: Readonly, { throw err; } Astro.response.headers.set('X-Load-Took', String(Date.now() - startedAt)); + if (import.meta.env.PROD) { + const { assetsPrefix } = config.settings; + if (assetsPrefix && assetsPrefix.startsWith('https://')) { + const cdnURL = assetsPrefix.replace(/(https:\/\/[^/]+).*/, '$1'); + Astro.response.headers.set('Link', `<${cdnURL}/>; rel=preconnect`); + } + } if (urlPath === '/~fallback') { setResponseCache(Astro, 3600, 86400); } else if (isHomepage) { diff --git a/packages/types/index.ts b/packages/types/index.ts index 912f3a97e..9183cfb13 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -100,6 +100,7 @@ type SettingsContent = { primaryColor: string, secondaryColor?: string, bgColor?: string, + assetsPrefix?: string, email: string, phone: string, address: string,