import appFetch from '../../utils/app-fetch'; import { Cache, CacheKey } from '../../lib/cache'; import { misc } from '../../data/urls'; import { ServerVariables } from '../../utils/server-variables'; interface SeoDataParams { url: string; locale?: string; currency?: string; headers?: Record; } function getSeoDataHandler({ url, locale, currency, headers }: SeoDataParams) { return async function () { let data = {} as { title: string; description: string; keywords: string; [key: string]: string; }; try { data = await appFetch({ url: misc.cmsSeo(url), locale, currency, init: { headers } }); } catch (error) { // logger.error('Error while fetching seo data', { url, error }); } return data; }; } export const getSeoData = async ( url, locale = ServerVariables.locale, currency = ServerVariables.currency, headers?: Record ) => { return Cache.wrap( CacheKey.Seo(url), locale, getSeoDataHandler({ url, locale, currency, headers }), { compressed: true } ); };