ucharles / gachatory

https://www.gachatory.com
0 stars 0 forks source link

Server Component에서 API를 호출할 때 인증 등으로 헤더, 쿠키 정보가 필요할 경우 따로 첨부하기 #76

Closed ucharles closed 7 months ago

ucharles commented 10 months ago

발단

문제

해결

import { cookies } from "next/headers";

export default async function Page({ params: { lng, id }, }: { params: { lng: string; id: string }; }) { const cookie = cookies(); const response = await fetch(API_URI + /api/capsules/${id}?lng=${lng}, { method: "GET", next: { revalidate: cacheTimeEnum.FIVE_MINUTES }, headers: { cookie: cookie, }, }); const data = await response.json(); }

ucharles commented 7 months ago

https://github.com/ucharles/gachatory/pull/94 에서 반영 완료