// Используется в клиентских компонентах ('use client'). Идёт через относительный // /api - в браузере это резолвится через Caddy, который проксирует на бэкенд. async function request(path, options = {}) { const res = await fetch(`/api${path}`, { credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, ...options, }); if (!res.ok) { let message = 'Request failed'; try { const data = await res.json(); message = data.error || message; } catch (e) { // no JSON body } throw new Error(message); } if (res.status === 204) return null; return res.json(); } export const clientApi = { submitReview: (data) => request('/reviews', { method: 'POST', body: JSON.stringify(data) }), trackVisit: () => request('/stats/visit', { method: 'POST' }).catch(() => {}), };