import { notFound } from "next/navigation"; import { headers } from "next/headers"; import { HeroBanner } from "@/app/components/HeroBanner"; import Link from "next/link"; import prisma from "@/lib/prisma"; function stripHtml(html: string | null | undefined): string { if (!html) return ""; return html.replace(/<[^>]*>/g, "").trim(); } // 서버 전용 페이지: 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; // 같은 게시판의 다른 게시글 10개 가져오기 (현재 게시글 제외) const relatedPosts = post?.boardId ? await prisma.post.findMany({ where: { boardId: post.boardId, id: { not: id }, status: { not: "deleted" }, }, orderBy: { createdAt: "desc" }, take: 10, select: { id: true, title: true, createdAt: true, author: { select: { nickname: true } }, stat: { select: { views: true, recommendCount: true, commentsCount: true } }, }, }) : []; return (
{/* 상단 배너 */}
{/* 본문 카드 */}

{post.title}

{createdAt && (

{createdAt.toLocaleString()}

)}
{/* 같은 게시판 게시글 목록 */} {relatedPosts.length > 0 && (

같은 게시판 게시글

    {relatedPosts.map((p) => { const postDate = new Date(p.createdAt); return (
  • {stripHtml(p.title)}
    {p.author?.nickname ?? "익명"}
    조회 {p.stat?.views ?? 0} 추천 {p.stat?.recommendCount ?? 0} 댓글 {p.stat?.commentsCount ?? 0}
    {postDate.toLocaleDateString()}
  • ); })}
)}
); }