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
27 lines
952 B
JavaScript
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(() => {}),
|
|
};
|