Skip to content

Commit

Permalink
feat(storefront): Handle optional settings.assetsPrefix field to su…
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Oct 13, 2023
1 parent 3e30407 commit 46d6c43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/storefront/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const deployRand = process.env.DEPLOY_RAND || '_';
const isLibDev = !(relativePath(__dirname, process.cwd()));

const {
storeId,
lang,
domain,
primaryColor,
Expand All @@ -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: [{
Expand Down Expand Up @@ -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,
Expand All @@ -229,7 +236,9 @@ const genAstroConfig = ({
site,
compressHTML: isToServerless,
build: {
assetsPrefix,
inlineStylesheets: 'never',
...settings.build,
},
vite: {
plugins: [
Expand Down
11 changes: 9 additions & 2 deletions packages/storefront/src/lib/ssr-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -179,6 +179,13 @@ const loadRouteContext = async (Astro: Readonly<AstroGlobal>, {
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) {
Expand Down
1 change: 1 addition & 0 deletions packages/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type SettingsContent = {
primaryColor: string,
secondaryColor?: string,
bgColor?: string,
assetsPrefix?: string,
email: string,
phone: string,
address: string,
Expand Down

0 comments on commit 46d6c43

Please sign in to comment.