diff --git a/src/app/boards/[id]/page.tsx b/src/app/boards/[id]/page.tsx index 4e366e3..dab7b80 100644 --- a/src/app/boards/[id]/page.tsx +++ b/src/app/boards/[id]/page.tsx @@ -1,18 +1,26 @@ import { PostList } from "@/app/components/PostList"; +import { headers } from "next/headers"; +import React, { use } from "react"; -export default async function BoardDetail({ params, searchParams }: { params: { id: string }; searchParams?: { sort?: "recent" | "popular" } }) { - const sort = searchParams?.sort ?? "recent"; +export default async function BoardDetail({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ sort?: "recent" | "popular" }> }) { + const { id } = use(params); + const sp = use(searchParams); + const sort = sp?.sort ?? "recent"; // 보드 slug 조회 (새 글 페이지 프리셋 전달) - const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL ?? ""}/api/boards`, { cache: "no-store" }); + 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/boards", base).toString(), { cache: "no-store" }); const { boards } = await res.json(); - const board = (boards || []).find((b: any) => b.id === params.id); + const board = (boards || []).find((b: any) => b.id === id); return (
); } diff --git a/src/app/boards/page.tsx b/src/app/boards/page.tsx index a5ea9a4..41edc89 100644 --- a/src/app/boards/page.tsx +++ b/src/app/boards/page.tsx @@ -1,5 +1,12 @@ +import { headers } from "next/headers"; + export default async function BoardsPage() { - const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL ?? ""}/api/boards`, { cache: "no-store" }); + 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 url = new URL("/api/boards", base).toString(); + const res = await fetch(url, { cache: "no-store" }); const { boards } = await res.json(); return ({post.content}