import { notFound } from "next/navigation"; import { headers } from "next/headers"; import { HeroBanner } from "@/app/components/HeroBanner"; import { RelatedPosts } from "./RelatedPosts"; import prisma from "@/lib/prisma"; import { CommentSection } from "@/app/components/CommentSection"; import { UserNameMenu } from "@/app/components/UserNameMenu"; import { ViewTracker } from "./ViewTracker"; // 서버 전용 페이지: params가 Promise일 수 있어 안전 언랩 후 절대 URL로 fetch합니다. export default async function PostDetail({ params }: { params: any }) { const p = params?.then ? await params : params; const id = p.id as string; // slug 값이 들어옴 const h = await headers(); const host = h.get("host") ?? "localhost:3000"; const proto = h.get("x-forwarded-proto") ?? "http"; const base = process.env.NEXT_PUBLIC_BASE_URL || `${proto}://${host}`; const res = await fetch(new URL(`/api/posts/${id}`, base).toString(), { cache: "no-store" }); if (!res.ok) return notFound(); const { post } = await res.json(); const createdAt = post?.createdAt ? new Date(post.createdAt) : null; // 메인배너 표시 설정 const SETTINGS_KEY = "mainpage_settings" as const; const settingRow = await prisma.setting.findUnique({ where: { key: SETTINGS_KEY } }); const parsed = settingRow ? JSON.parse(settingRow.value as string) : {}; const showBanner: boolean = parsed.showBanner ?? true; // 현재 게시글이 속한 카테고리의 보드들을 서브카테고리로 구성 let subItems: | { id: string; name: string; href: string }[] | undefined = undefined; if (post?.boardId) { const categories = await prisma.boardCategory.findMany({ where: { status: "active" }, orderBy: [{ sortOrder: "asc" }, { createdAt: "asc" }], include: { boards: { where: { status: "active" }, orderBy: [{ sortOrder: "asc" }, { createdAt: "asc" }], select: { id: true, name: true, slug: true }, }, }, }); const categoryOfPost = categories.find((c) => c.boards.some((b) => b.id === post.boardId) ); if (categoryOfPost) { subItems = categoryOfPost.boards.map((b) => ({ id: b.id, name: b.name, href: `/boards/${b.slug}`, })); } } return (