Files
msgapp/src/app/posts/[id]/page.tsx

32 lines
1.2 KiB
TypeScript
Raw Normal View History

import { notFound } from "next/navigation";
2025-10-10 14:39:22 +09:00
import { headers } from "next/headers";
// 서버 전용 페이지: 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;
2025-10-10 14:39:22 +09:00
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();
return (
<div>
<h1>{post.title}</h1>
<div style={{ display: "flex", gap: 8, margin: "8px 0" }}>
2025-10-10 14:39:22 +09:00
<form action={`/api/posts/${post.id}/recommend`} method="post">
<button type="submit"></button>
</form>
<form action={`/api/posts/${post.id}/report`} method="post">
<button type="submit"></button>
</form>
</div>
<p style={{ whiteSpace: "pre-wrap" }}>{post.content}</p>
</div>
);
}