1 Commits

Author SHA1 Message Date
Nermin Karic
899ed44562 fix: webpack build, low memory limits, and sitemap try/catch for Docker deploy
- Switch both storefronts from Turbopack to Webpack (next build --webpack)
- Limit build workers to 1 CPU (experimental.cpus: 1)
- Reduce NODE_OPTIONS max-old-space-size from 2048 to 1024 MB
- Wrap sitemap.ts API calls in try/catch to prevent build crash when backend is unavailable during Docker build
- During build, sitemap returns static paths only; at runtime it fetches full dynamic data
2026-11-23 01:59:50 +01:00
2 changed files with 94 additions and 72 deletions

View File

@@ -30,43 +30,54 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
type Entry = { handle?: string | null; updated_at?: string | Date | null } type Entry = { handle?: string | null; updated_at?: string | Date | null }
export default async function sitemap(): Promise<MetadataRoute.Sitemap> { export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE } const origin = await getSiteOrigin()
const [origin, regions, products, categories, collections] = await Promise.all([ try {
getSiteOrigin(), const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({ items: res.product_categories, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
const toEntries = (base: string, prefix: string, items: Entry[]) => const [regions, products, categories, collections] = await Promise.all([
items listRegions(),
.filter((item) => item.handle) listAll<Entry>((offset) =>
.map((item) => ({ sdk.store.product
url: `${base}/${prefix}/${item.handle}`, .list({ ...query, offset })
lastModified: item.updated_at ? new Date(item.updated_at) : undefined, .then((res) => ({ items: res.products, count: res.count }))
})) ),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({
items: res.product_categories,
count: res.count,
}))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
return listCountryCodes(regions).flatMap((countryCode) => { const toEntries = (base: string, prefix: string, items: Entry[]) =>
const base = `${origin}/${countryCode}` items
return [ .filter((item) => item.handle)
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })), .map((item) => ({
...toEntries(base, "products", products), url: `${base}/${prefix}/${item.handle}`,
...toEntries(base, "categories", categories), lastModified: item.updated_at
...toEntries(base, "collections", collections), ? new Date(item.updated_at)
] : undefined,
}) }))
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
} catch {
// During Docker build the backend is not running — return static paths only
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
}
} }

View File

@@ -30,43 +30,54 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
type Entry = { handle?: string | null; updated_at?: string | Date | null } type Entry = { handle?: string | null; updated_at?: string | Date | null }
export default async function sitemap(): Promise<MetadataRoute.Sitemap> { export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE } const origin = await getSiteOrigin()
const [origin, regions, products, categories, collections] = await Promise.all([ try {
getSiteOrigin(), const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({ items: res.product_categories, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
const toEntries = (base: string, prefix: string, items: Entry[]) => const [regions, products, categories, collections] = await Promise.all([
items listRegions(),
.filter((item) => item.handle) listAll<Entry>((offset) =>
.map((item) => ({ sdk.store.product
url: `${base}/${prefix}/${item.handle}`, .list({ ...query, offset })
lastModified: item.updated_at ? new Date(item.updated_at) : undefined, .then((res) => ({ items: res.products, count: res.count }))
})) ),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({
items: res.product_categories,
count: res.count,
}))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
return listCountryCodes(regions).flatMap((countryCode) => { const toEntries = (base: string, prefix: string, items: Entry[]) =>
const base = `${origin}/${countryCode}` items
return [ .filter((item) => item.handle)
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })), .map((item) => ({
...toEntries(base, "products", products), url: `${base}/${prefix}/${item.handle}`,
...toEntries(base, "categories", categories), lastModified: item.updated_at
...toEntries(base, "collections", collections), ? new Date(item.updated_at)
] : undefined,
}) }))
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
} catch {
// During Docker build the backend is not running — return static paths only
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
}
} }