-
Notifications
You must be signed in to change notification settings - Fork 20
[황혜진] sprint5 #64
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
The head ref may contain hidden characters: "React-\uD669\uD61C\uC9C4-sprint5"
[황혜진] sprint5 #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| REACT_APP_BASE_URL=https://panda-market-api.vercel.app | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 환경변수를
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,32 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <html lang="ko"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <meta name="theme-color" content="#000000" /> | ||
| <meta | ||
| name="description" | ||
| content="Web site created using create-react-app" | ||
| /> | ||
| <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
| <!-- | ||
| manifest.json provides metadata used when your web app is installed on a | ||
| user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
| --> | ||
| <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
| <!-- | ||
| Notice the use of %PUBLIC_URL% in the tags above. | ||
| It will be replaced with the URL of the `public` folder during the build. | ||
| Only files inside the `public` folder can be referenced from the HTML. | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>판다마켓</title> | ||
|
|
||
| Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
| work correctly both with client-side routing and a non-root public URL. | ||
| Learn how to configure a non-root public URL by running `npm run build`. | ||
| <!-- | ||
| Font preloading | ||
| - 페이지가 처음 로딩될 때 텍스트가 순간적으로 깜빡이거나 바뀌는 듯한 현상을 보신 적이 있으신가요? (Flash of Unstyled Text, FOUT) | ||
| 브라우저가 지정된 폰트를 다운로드 받는 동안 임시로 대체 폰트("fallback font")를 사용하기 때문인데요, 폰트를 preload하면 텍스트 렌더링을 보다 매끄럽게 할 수 있습니다. | ||
| - 브라우저는 rel="preload"로 지정된 리소스를 우선적으로 준비합니다. | ||
| - 폰트, 페이지 상단의 이미지, 가장 먼저 실행되어야 하는 스크립트 등에 preload 속성을 사용하는 경우가 많아요. | ||
| - href의 리소스 유형에 따라 <link>의 `as` 속성값을 정해야 해요. 일반적인 폰트 파일(예: .woff, .ttf 등)이라면 as="font"겠지만, 우리가 사용하는 웹폰트는 css 형식이기 때문에 as="style"을 사용합니다. | ||
| --> | ||
| <title>React App</title> | ||
| <link | ||
| rel="preload" | ||
| href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" | ||
| as="style" | ||
| onload="this.onload=null;this.rel='stylesheet'" | ||
| /> | ||
| <!-- 간혹 보안 등의 이슈로 자바스크립트를 지원하지 않는 브라우저 환경에서도 최소한의 스타일이 로딩될 수 있도록 합니다. --> | ||
| <noscript | ||
| ><link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" | ||
| /></noscript> | ||
| </head> | ||
| <body> | ||
| <noscript>You need to enable JavaScript to run this app.</noscript> | ||
| <div id="root"></div> | ||
| <!-- | ||
| This HTML file is a template. | ||
| If you open it directly in the browser, you will see an empty page. | ||
|
|
||
| You can add webfonts, meta tags, or analytics to this file. | ||
| The build step will place the bundled scripts into the <body> tag. | ||
|
|
||
| To begin the development, run `npm start` or `yarn start`. | ||
| To create a production bundle, use `npm run build` or `yarn build`. | ||
| --> | ||
| </body> | ||
| </html> |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,40 @@ | ||||||||||||||||||||||||||||||
| //itemApi.js | ||||||||||||||||||||||||||||||
| const BASE_URL = process.env.REACT_APP_BASE_URL; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // export async function getProducts(params = {}) { | ||||||||||||||||||||||||||||||
| // // URLSearchParams을 이용하면 파라미터 값을 자동으로 쉽게 인코딩할 수 있어요. | ||||||||||||||||||||||||||||||
| // const query = new URLSearchParams(params).toString(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // try { | ||||||||||||||||||||||||||||||
| // const response = await fetch(`${BASE_URL}/products?${query}`); | ||||||||||||||||||||||||||||||
| // if (!response.ok) { | ||||||||||||||||||||||||||||||
| // throw new Error(`HTTP error: ${response.status}`); | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| // const body = await response.json(); | ||||||||||||||||||||||||||||||
| // return body; | ||||||||||||||||||||||||||||||
| // } catch (error) { | ||||||||||||||||||||||||||||||
| // console.error("Failed to fetch products:", error); | ||||||||||||||||||||||||||||||
| // throw error; | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export async function getProducts({ page, pageSize, orderBy, keyword }) { | ||||||||||||||||||||||||||||||
| const queryParams = new URLSearchParams({ | ||||||||||||||||||||||||||||||
| page, | ||||||||||||||||||||||||||||||
| pageSize, | ||||||||||||||||||||||||||||||
| orderBy, | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+26
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오우 !
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (keyword) { | ||||||||||||||||||||||||||||||
| queryParams.append("keyword", keyword); | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음 코드와 똑같지 않을까 예상됩니다 !
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const response = await fetch( | ||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. axios를 사용해보는건 어떨까요?(제안/선택)
어떻게 세팅하면 될까? 🤔
const baseURL = process.env.NEXT_PUBLIC_LINKBRARY_BaseURL;
const instance = axios.create({
baseURL: baseURL,
headers: {
'Content-Type': 'application/json',
},
});
export default instance인가에 필요한
사용 방법 🚀사용 방법은 정말 간단해요. 다음과 같이 사용할 수 있습니다: instance.get(`/user/${userId}`)딱 보니. 마이그레이션도 정말 쉽게 할 수 있겠죠? 😊 |
||||||||||||||||||||||||||||||
| `https://panda-market-api.vercel.app/products?${queryParams.toString()}` | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+35
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||
| const response = await fetch( | |
| `https://panda-market-api.vercel.app/products?${queryParams.toString()}` | |
| ); | |
| if (!response.ok) { | |
| const response = await fetch( | |
| `${BASE_URL}/products?${queryParams.toString()}` | |
| ); | |
| if (!response.ok) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| .headerLeft { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .headerLogo { | ||
| margin-right: 16px; | ||
| } | ||
|
|
||
| .globalHeader nav ul { | ||
| display: flex; | ||
| list-style: none; | ||
| gap: 8px; | ||
| font-weight: bold; | ||
| font-size: 16px; | ||
| color: #4b5563; | ||
| } | ||
|
|
||
| .globalHeader nav ul li a:hover { | ||
| color: var(--blue); | ||
| } | ||
|
|
||
| .loginLink { | ||
| font-size: 16px; | ||
| font-weight: 600; | ||
| border-radius: 8px; | ||
| padding: 11.5px 23px; | ||
| } | ||
|
|
||
| @media (min-width: 768px) { | ||
| .globalHeader nav ul { | ||
| gap: 36px; | ||
| font-size: 18px; | ||
| } | ||
|
|
||
| .headerLogo { | ||
| margin-right: 35px; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 1280px) { | ||
| .headerLogo { | ||
| margin-right: 47px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import React from "react"; | ||
| import Logo from "../../assets/images/logo/logo.svg"; | ||
| import { Link, NavLink } from "react-router-dom"; | ||
| import "./Header.css"; | ||
|
|
||
| // react-router-dom의 NavLink를 이용하면 활성화된 네비게이션 항목을 하이라이트해줄 수 있어요! | ||
| function getLinkStyle({ isActive }) { | ||
| return { color: isActive ? "var(--blue)" : undefined }; | ||
| } | ||
|
|
||
| function Header() { | ||
| return ( | ||
| <header className="globalHeader"> | ||
| <div className="headerLeft"> | ||
| <Link to="/" className="headerLogo" aria-label="홈으로 이동"> | ||
| <img src={Logo} alt="판다마켓 로고" width="153" /> | ||
| </Link> | ||
|
|
||
| <nav> | ||
| <ul> | ||
| <li> | ||
| <NavLink to="/community" style={getLinkStyle}> | ||
| 자유게시판 | ||
| </NavLink> | ||
| </li> | ||
| <li> | ||
| <NavLink to="/items" style={getLinkStyle}> | ||
| 중고마켓 | ||
| </NavLink> | ||
| </li> | ||
| </ul> | ||
| </nav> | ||
| </div> | ||
|
|
||
| <Link to="/login" className="loginLink button"> | ||
| 로그인 | ||
| </Link> | ||
| </header> | ||
| ); | ||
| } | ||
|
|
||
| export default Header; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
훌륭합니다 ! 환경변수로
BASE_URL을 지정하셨군요 !굿굿 ~! 환경변수는 다음과 같은 이점들이 있지요:
왜 환경 변수에 저장해야 하나요?
개발(
dev), 테스트(test), 실제 사용(prod) 등 다양한 환경에서 앱을 운영하게 되는 경우, 각 환경에 따라 다른 base URL을 사용해야 할 수 있습니다. 만약 코드 내에 하드코딩되어 있다면, 각 환경에 맞춰 앱을 배포할 때마다 코드를 변경해야 하며, 이는 매우 번거로운 작업이 됩니다. 하지만, 환경 변수를.env.production,.env.development,.env.test와 같이 설정해두었다면, 코드에서는 단지 다음과 같이 적용하기만 하면 됩니다.이러한 방식으로 환경 변수를 사용하면, 배포 환경에 따라 쉽게 URL을 변경할 수 있으며, 코드의 가독성과 유지보수성도 개선됩니다.
실제 코드 응용과 관련해서는 다음 한글 아티클을 참고해보세요! => 보러가기