// src/pages/api/load-posts/index.ts import type { APIRoute } from 'astro'; export const POST: APIRoute = async ({ request }) => { try { const body = await request.json(); const { after = null, first = 8 } = body; // Динамический импорт const { getLatestPosts } = await import('../../../../lib/api/posts.js'); const { posts, pageInfo } = await getLatestPosts(first, after); return new Response( JSON.stringify({ success: true, posts, pageInfo }), { status: 200, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'public, max-age=60' } } ); } catch (error) { console.error('Error loading posts:', error); return new Response( JSON.stringify({ success: false, error: 'Failed to load posts', posts: [], pageInfo: { hasNextPage: false, endCursor: null } }), { status: 500, headers: { 'Content-Type': 'application/json' } } ); } }; export const prerender = false;