24 lines
669 B
TypeScript
24 lines
669 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getPostBySlug } from "@/lib/blog";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
|
|
try {
|
|
const { slug } = await params;
|
|
const post = await getPostBySlug(slug);
|
|
|
|
if (!post) {
|
|
return NextResponse.json({ success: false, error: "Post not found" }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
post,
|
|
});
|
|
} catch (error) {
|
|
console.error("API Error:", error);
|
|
return NextResponse.json({ success: false, error: "Failed to fetch post" }, { status: 500 });
|
|
}
|
|
}
|