// apps/dm/src/entities/content/ // contents-api.ts import { unstable_cache } from "next/cache"; import { ENDPOINT } from "@/src/shared/config"; function getServerBaseUrl() { const port = process.env.PORT ?? process.env.NEXT_PUBLIC_PORT ?? "3000"; const proxyHost = process.env.NEXT_PUBLIC_PROXY_HOST; if (process.env.NODE_ENV === "production" && process.env.HOSTNAME) { return `http://${process.env.HOSTNAME}:${port}`; } return proxyHost || `http://localhost:${port}`; } export const getCachedContentDetail = unstable_cache( async (contsSn: number, menuCd: string) => { const baseUrl = getServerBaseUrl(); const res = await fetch( `${baseUrl}${ENDPOINT.CMS_SERVICE.CONTENTS}/${contsSn}?menuCd=${menuCd}`, { next: { revalidate: 0, tags: [`content:${contsSn}`] }, } ); if (!res.ok) { console.log(res); throw new Error("Failed to fetch content"); } return res.json(); }, ["dm-content-detail"], { revalidate: 86400, // 1시간마다 자동 갱신 (선택 사항) tags: ["dm-content-detail"], // 여기에 태그를 명시해야 revalidateTag가 작동합니다. } );