Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[사전 미션 - CSR을 SSR로 재구성하기] - 시모(심호림) 미션 제출합니다. #37

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 69 additions & 10 deletions ssr/server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,78 @@
import { Router } from "express";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import {
fetchNowPlayingMovies,
fetchPopularMovies,
fetchTopRatedMovies,
fetchUpcomingMovies,
generateRenderedMovieItemsHTML,
} from "../../src/movies.js";
import {
fetchMovieItemDetail,
generateRenderedModalHTML,
} from "../../src/modal.js";

const router = Router();

router.get("/", (_, res) => {
const templatePath = path.join(__dirname, "../../views", "index.html");
const moviesHTML = "<p>들어갈 본문 작성</p>";
router.get("/", async (_, res) => {
const movies = await fetchNowPlayingMovies();
const renderedHTML = generateRenderedMovieItemsHTML(
movies.results,
"nowPlaying"
);

const template = fs.readFileSync(templatePath, "utf-8");
const renderedHTML = template.replace("<!--${MOVIE_ITEMS_PLACEHOLDER}-->", moviesHTML);
res.send(renderedHTML);
});

router.get("/now-playing", async (_, res) => {
const movies = await fetchNowPlayingMovies();
const renderedHTML = generateRenderedMovieItemsHTML(
movies.results,
"nowPlaying"
);

res.send(renderedHTML);
});

router.get("/popular", async (_, res) => {
const movies = await fetchPopularMovies();
const renderedHTML = generateRenderedMovieItemsHTML(
movies.results,
"popular"
);

res.send(renderedHTML);
});

router.get("/top-rated", async (_, res) => {
const movies = await fetchTopRatedMovies();
const renderedHTML = generateRenderedMovieItemsHTML(
movies.results,
"topRated"
);

res.send(renderedHTML);
});

router.get("/upcoming", async (_, res) => {
const movies = await fetchUpcomingMovies();
const renderedHTML = generateRenderedMovieItemsHTML(
movies.results,
"upcoming"
);

res.send(renderedHTML);
});

router.get("/detail/:id", async (req, res) => {
const id = req.params.id;
const movieItems = await fetchNowPlayingMovies();
const movieDetail = await fetchMovieItemDetail(id);

const renderedHTML = generateRenderedModalHTML(
movieItems.results,
movieDetail
);

res.send(renderedHTML);
});
Expand Down
Binary file added ssr/src/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/src/assets/images/modal_button_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/src/assets/images/star_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/src/assets/images/star_filled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/src/assets/images/woowacourse_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions ssr/src/assets/styles/colors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:root {
--color-white: #ffffff;
--color-lightblue-90: #0da9fd;
--color-bluegray-100: #242a32;
--color-bluegray-80: #39414d;
--color-bluegray-10: #e0e6ed;
--color-bluegray-30: #a6b1c3;
--color-bluegray-90: #2f3844;
--color-gray-300: #d1d3d4;
--color-yellow: #ffc700;
--color-ffffff: #ffffff;
--color-242a32: #242a32;
}
134 changes: 134 additions & 0 deletions ssr/src/assets/styles/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
@import "./colors.css";

* {
box-sizing: border-box;
}

a {
color: inherit;
text-decoration: none;
}

body {
font-size: 16px;
color: var(--color-white);
background-color: var(--color-bluegray-80);
}

#wrap,
section {
display: flex;
flex-direction: column;
justify-content: center;
}

main {
margin-bottom: 64px;
}

.star {
width: 24px;
}

button {
border: 0;
padding: 8px 16px;
cursor: pointer;
}

button.primary {
color: var(--color-white);
font-weight: bold;
background-color: var(--color-lightblue-90);
border-radius: 4px;
}

#wrap {
min-width: 1440px;
background-color: var(--color-bluegray-100);
}

#wrap h2 {
font-size: 1.4rem;
font-weight: bold;
margin-bottom: 32px;
}

.container {
max-width: 1280px;
margin: 0 auto;
}

.background-container {
position: relative;
background-position: center center;
background-size: cover;
height: 500px;
padding: 48px;
}

.overlay {
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
height: 100%;
z-index: 1;
}

.top-rated-container {
user-select: none;
position: relative;
z-index: 2;
max-width: 1280px;
margin: 0 auto;
}

.top-rated-movie {
margin-top: 64px;
}

.top-rated-movie > *:not(:last-child) {
margin-bottom: 8px;
}

h1.logo {
font-size: 2rem;
}

.rate {
display: flex;
align-items: baseline;
color: var(--color-yellow);
}

.rate > img {
position: relative;
top: 2px;
}

span.rate-value {
margin-left: 8px;
font-weight: bold;
font-size: 1.66rem;
}

.title {
font-size: 3rem;
font-weight: bold;
}

footer.footer {
min-height: 180px;
background-color: var(--color-bluegray-80);
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
font-size: 1.1rem;
}

footer.footer p:not(:last-child) {
margin-bottom: 8px;
}
88 changes: 88 additions & 0 deletions ssr/src/assets/styles/modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@import "./colors.css";

/* modal.css */
body.modal-open {
overflow: hidden;
}

.modal-background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* 반투명 배경을 위해 설정 */
backdrop-filter: blur(10px); /* 블러 효과 적용 */
display: flex;
justify-content: center;
align-items: center;
z-index: 10;
visibility: hidden; /* 모달이 기본적으로 보이지 않도록 설정 */
opacity: 0;
transition:
opacity 0.3s ease,
visibility 0.3s ease;
}

.modal-background.active {
visibility: visible;
opacity: 1;
}

.modal {
background-color: var(--color-bluegray-90);
padding: 20px;
border-radius: 16px;
color: white;
z-index: 2;
position: relative;
width: 1000px;
}

.close-modal {
position: absolute;
margin: 0;
padding: 0;
top: 24px;
right: 24px;
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
}

.modal-container {
display: flex;
}

.modal-image img {
width: 380px;
border-radius: 16px;
}

.modal-description {
width: 100%;
padding: 8px;
margin-left: 16px;
line-height: 1.6rem;
}

.modal-description .rate > img {
position: relative;
top: 5px;
}

.modal-description > *:not(:last-child) {
margin-bottom: 8px;
}

.modal-description h2 {
font-size: 2rem;
margin: 0 0 8px;
}

.detail {
max-height: 430px;
overflow-y: auto;
}
Loading