Files
topsysops-app/public-site/lib/clientApi.js
T
ogrechkoandClaude Sonnet 5 130c5382cd Initial commit: TopSysOps site + admin panel
Multi-page public site (Next.js), Node/Express backend with Postgres,
and Vite admin/account app, restructured from a single-page layout
into dedicated service, promotions, cases, about, FAQ, and blog pages
for SEO.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013otXCiTZsxdZ4SJKZ9wUky
2026-08-25 23:12:16 +03:00

27 lines
952 B
JavaScript

// Используется в клиентских компонентах ('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(() => {}),
};