From 302b325487739e1300fbc852fe0f89d578e0e1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=97=A4=EC=9D=B8?= <157036488+Hain-tain@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:43:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=AA=A8=EB=8B=AC=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ssr/server/routes/index.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/ssr/server/routes/index.js b/ssr/server/routes/index.js index f59f241..1a86f4e 100644 --- a/ssr/server/routes/index.js +++ b/ssr/server/routes/index.js @@ -2,8 +2,12 @@ import { Router } from 'express'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; -import { fetchMovies, renderMovieItem } from './utils.js'; -import { TMDB_BANNER_URL, TMDB_MOVIE_LISTS } from '../src/constant.js'; +import { fetchMovies, renderMovieItem, renderDetailModal } from './utils.js'; +import { + TMDB_BANNER_URL, + TMDB_MOVIE_LISTS, + TMDB_MOVIE_DETAIL_URL, +} from '../src/constant.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -129,4 +133,33 @@ router.get('/upcoming', async (_, res) => { res.send(renderedHTML); }); +router.get('/detail/:id', async (req, res) => { + const templatePath = path.join(__dirname, '../../views', 'index.html'); + const movieId = req.params.id; + + const responseFetchMovies = await fetchMovies(TMDB_MOVIE_LISTS.NOW_PLAYING); + const movieList = responseFetchMovies.results; + + const moviesHTML = renderMovieItem(movieList).join(''); + + const movieDetail = await fetchMovies( + `${TMDB_MOVIE_DETAIL_URL}/${movieId}?language=ko-KR` + ); + + const template = fs.readFileSync(templatePath, 'utf-8'); + + const renderedHTML = template + .replace('', moviesHTML) + .replace( + '${background-container}', + `${TMDB_BANNER_URL}${movieList[0].backdrop_path}` + ) + .replace('${bestMovie.rate}', movieList[0].vote_average) + .replace('${bestMovie.title}', movieList[0].title) + .replace('${TAB_NOW_PLAYING}', 'selected') + .replace('', renderDetailModal(movieDetail)); + + res.send(renderedHTML); +}); + export default router;