1 Commits

Author SHA1 Message Date
Nermin Karic
45b58d1d9a fix: use webpack and 1 worker for low-memory storefront builds 2026-11-23 01:48:00 +01:00
2 changed files with 72 additions and 94 deletions

View File

@@ -30,54 +30,43 @@ 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 origin = await getSiteOrigin() const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
try { const [origin, regions, products, categories, collections] = await Promise.all([
const query = { fields: "handle,updated_at", limit: PAGE_SIZE } getSiteOrigin(),
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 [regions, products, categories, collections] = await Promise.all([ const toEntries = (base: string, prefix: string, items: Entry[]) =>
listRegions(), items
listAll<Entry>((offset) => .filter((item) => item.handle)
sdk.store.product .map((item) => ({
.list({ ...query, offset }) url: `${base}/${prefix}/${item.handle}`,
.then((res) => ({ items: res.products, count: res.count })) lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
), }))
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[]) => return listCountryCodes(regions).flatMap((countryCode) => {
items const base = `${origin}/${countryCode}`
.filter((item) => item.handle) return [
.map((item) => ({ ...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
url: `${base}/${prefix}/${item.handle}`, ...toEntries(base, "products", products),
lastModified: item.updated_at ...toEntries(base, "categories", categories),
? new Date(item.updated_at) ...toEntries(base, "collections", collections),
: 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,54 +30,43 @@ 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 origin = await getSiteOrigin() const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
try { const [origin, regions, products, categories, collections] = await Promise.all([
const query = { fields: "handle,updated_at", limit: PAGE_SIZE } getSiteOrigin(),
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 [regions, products, categories, collections] = await Promise.all([ const toEntries = (base: string, prefix: string, items: Entry[]) =>
listRegions(), items
listAll<Entry>((offset) => .filter((item) => item.handle)
sdk.store.product .map((item) => ({
.list({ ...query, offset }) url: `${base}/${prefix}/${item.handle}`,
.then((res) => ({ items: res.products, count: res.count })) lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
), }))
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[]) => return listCountryCodes(regions).flatMap((countryCode) => {
items const base = `${origin}/${countryCode}`
.filter((item) => item.handle) return [
.map((item) => ({ ...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
url: `${base}/${prefix}/${item.handle}`, ...toEntries(base, "products", products),
lastModified: item.updated_at ...toEntries(base, "categories", categories),
? new Date(item.updated_at) ...toEntries(base, "collections", collections),
: 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}` }))
}
} }