// Определяет страну клиента и кладёт ISO-код в event.context.clientCountryCode: // сначала из cookie `clientCountryCode` (ручной выбор в селекторе), иначе из // заголовков прокси (Cloudflare `cf-ipcountry` / `x-country-code` / `x-country`). export default defineEventHandler((event) => { const cookie = getCookie(event, 'clientCountryCode'); if (cookie) { event.context.clientCountryCode = cookie.trim().toLowerCase(); return; } const headers = event.node.req.headers; const code = (headers['cf-ipcountry'] || headers['x-country-code'] || headers['x-country']) as string | undefined; event.context.clientCountryCode = code?.trim().toLowerCase() || ''; });