Files
zeropost-web/lib/engine.js
T
Alexey Pavlov 6dfe8b8afa feat: zeropost-web — публичный AI-блог на zeropost.ru
- Next.js 16, Tailwind с @tailwindcss/typography
- Главная: hero, featured-статья, сетка карточек, облако тегов
- /blog/[slug]: статья со SSG + revalidate 60s, prose typography
- /tag/[name]: фильтр по тегам
- /about: про проект
- /api/cron/generate: endpoint для авто-генерации (защищён x-cron-token)
- SEO: dynamic metadata, OG, sitemap-ready
- Лента грузится с zeropost-engine /api/articles
2026-05-31 08:50:35 +03:00

46 lines
1.2 KiB
JavaScript

const ENGINE_URL = process.env.ENGINE_URL || 'http://127.0.0.1:3040';
const ENGINE_SECRET = process.env.ENGINE_SECRET || 'zeropost_internal_2026';
async function call(path, options = {}) {
const res = await fetch(`${ENGINE_URL}${path}`, {
...options,
headers: {
'Content-Type': 'application/json',
'x-internal-secret': ENGINE_SECRET,
...(options.headers || {}),
},
cache: options.cache || 'no-store',
next: options.next,
});
if (!res.ok) {
const txt = await res.text();
throw new Error(`Engine ${res.status}: ${txt}`);
}
return res.json();
}
export async function listArticles({ limit = 20, offset = 0, tag } = {}) {
const params = new URLSearchParams({ limit, offset });
if (tag) params.set('tag', tag);
return call(`/api/articles?${params}`, { next: { revalidate: 60 } });
}
export async function getArticle(slug) {
try {
return await call(`/api/articles/${slug}`, { next: { revalidate: 60 } });
} catch {
return null;
}
}
export async function listTags() {
return call('/api/articles/tags', { next: { revalidate: 300 } });
}
export async function generateArticle(data) {
return call('/api/articles/generate', {
method: 'POST',
body: JSON.stringify(data),
});
}