sztucznainteligencjadlafirm/app/api/blog/route.ts
Adrian Miesikowski a10d92abac first commit
2026-02-10 13:34:42 +01:00

23 lines
643 B
TypeScript

import { NextResponse } from "next/server";
import { getAllPosts } from "@/lib/blog";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const category = searchParams.get("category") as "case-study" | "blog" | null;
const posts = await getAllPosts(category || undefined);
return NextResponse.json({
success: true,
posts,
count: posts.length,
});
} catch (error) {
console.error("API Error:", error);
return NextResponse.json({ success: false, error: "Failed to fetch posts" }, { status: 500 });
}
}