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 }); } }