/page.tsx

import Link from "next/link";

export const metadata = {
    title: "Home"
}

const API_URL = "<https://nomad-movies.nomadcoders.workers.dev/movies>"

async function getMovies() {
    await new Promise((response) => setTimeout(response, 5000))
    const response = await fetch(API_URL)
    const json = await response.json()
    return json
}

export default async function HomePage() {
    const movies = await getMovies()
    return (
        <div>
            {movies.map((movie) => (
                <li key={movie.id}>
                    <Link href={`/movies/${movie.id}`}>{movie.title}</Link>
                </li>
            ))}
        </div>
    )
}

/movies/[id]/page.tsx

const API_URL = "<https://nomad-movies.nomadcoders.workers.dev/movies>"

async function getMovie(id: string) {
    const response = await fetch(`${API_URL}/${id}`)
    return response.json()
}

async function getVideos(id: string) {
    const response = await fetch(`${API_URL}/${id}/videos`)
    return response.json()
}

export default async function MovieDetail({params: {id}}: {params: {id: string}}) {
    const [movie, videos] = await Promise.all([getMovie(id), getVideos(id)])
    return <h1>{movie.title}</h1>
}

Next.js 영화 상세 페이지 구현 및 데이터 페칭 최적화

1. 영화 목록 렌더링

2. 영화 상세 페이지 구현

3. 페칭 캐싱 및 로딩 시간 조절

4. 추가 데이터 페칭 구현