| | import type { Response, NextFunction } from 'express' |
| |
|
| | import type { ExtendedRequest } from '@/types' |
| | import { getProductGroups } from '@/products/lib/get-product-groups' |
| | import warmServer from '@/frame/lib/warm-server' |
| | import { languageKeys } from '@/languages/lib/languages-server' |
| | import { allVersionKeys } from '@/versions/lib/all-versions' |
| |
|
| | const isHomepage = (path: string) => { |
| | const split = path.split('/') |
| | |
| | if (split.length === 2 && split[1] && !split[0]) { |
| | return languageKeys.includes(split[1]) |
| | } |
| | |
| | |
| | if (split.length === 3 && !split[0] && split[2]) { |
| | return allVersionKeys.includes(split[2]) |
| | } |
| | return false |
| | } |
| |
|
| | export default async function productGroups( |
| | req: ExtendedRequest, |
| | res: Response, |
| | next: NextFunction, |
| | ) { |
| | if (!req.context) throw new Error('request is not contextualized') |
| | if (!req.pagePath) throw new Error('pagePath is not set on request') |
| | if (!req.language) throw new Error('language is not set on request') |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | if (isHomepage(req.pagePath) && req.context.currentVersionObj) { |
| | const { pages } = await warmServer([]) |
| | req.context.productGroups = await getProductGroups(pages, req.language, req.context) |
| | } |
| |
|
| | return next() |
| | } |
| |
|