Files
topsysops-app/public-site/lib/serverApi.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
1.2 KiB
JavaScript

// Используется только внутри Server Component'ов (во время SSR/сборки).
// Обращается к бэкенду напрямую по внутреннему docker-адресу, минуя Caddy -
// это работает только на сервере Next.js, у браузера такого адреса нет.
const BASE = process.env.BACKEND_INTERNAL_URL || 'http://backend:4000';
async function get(path, { revalidate = 60 } = {}) {
try {
const res = await fetch(`${BASE}/api${path}`, { next: { revalidate } });
if (!res.ok) return null;
return res.json();
} catch (err) {
console.error(`[serverApi] failed to fetch ${path}`, err.message);
return null;
}
}
export const serverApi = {
getServices: () => get('/services').then((v) => v || []),
getPromotions: () => get('/promotions').then((v) => v || []),
getReviews: () => get('/reviews').then((v) => v || []),
getCases: () => get('/cases').then((v) => v || []),
getFaqs: () => get('/faqs').then((v) => v || []),
getContact: () => get('/contact'),
getBlogPosts: () => get('/blog').then((v) => v || []),
getBlogPost: (slug) => get(`/blog/${slug}`, { revalidate: 60 }),
};