add files

This commit is contained in:
Andrey Kuvshinov
2025-12-11 01:12:45 +03:00
commit 22358272c6
31 changed files with 7392 additions and 0 deletions

49
src/lib/api/load-posts.ts Normal file
View File

@@ -0,0 +1,49 @@
// 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;