Skip to content

Commit a6fcfc3

Browse files
authored
Merge pull request #38 from gpdnjs8/main
9, 10주차 - 위니/최혜원 워크북 과제 제출
2 parents 97e9f91 + 34ea890 commit a6fcfc3

4 files changed

Lines changed: 207 additions & 0 deletions

File tree

week09/keyword/keyword.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- OAuth 2.0
2+
3+
사용자가 비밀번호를 직접 넘기지 않고도, 타 사이트의 인증을 이용해 권한을 위임받는 표준 프로토콜(비밀번호 대신 토큰으로 권한을 위임하는 로그인/인증 표준)
4+
5+
특징
6+
7+
- AccessToken을 발급받아 API 접근
8+
- 소셜 로그인(구글 로그인, 카카오 로그인) 등 다양한 서비스와 연동 쉬움
9+
- 다양한 Grant Type 존재(Authorization Code, Client Credentials 등)
10+
- JWT
11+
12+
사용자 정보를 JSON 형태로 인코딩하여 전달하는 자체 서명 토큰
13+
14+
보통 AccessToken으로 사용됨
15+
16+
특징
17+
18+
- Header + Payload + Signature 구조
19+
- 서버가 상태(Session)를 저장할 필요x
20+
- Bearer Token
21+
22+
이 토큰을 가진 사람은 누구든 접근 가능하다는 방식의 단순한 인증 토큰
23+
24+
HTTP 헤더에 `Authorization: Bearer <token>` 으로 전송

week09/mission/mission.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
## 사용자 정보 관련하여 수정
3+
4+
### 내가 작성한 리뷰 목록 조회 API, 내가 진행 중인 미션 목록 조회 API
5+
6+
path parameter (:userId) 제거
7+
8+
- 로그인한 사용자의 ID는 이미 isLogin 미들웨어를 통해 req.user에 담겨 있기 때문
9+
10+
controller 수정
11+
12+
- 기존
13+
14+
```jsx
15+
export const handleListUserReviews = async (req, res, next) => {
16+
const reviews = await listUserReviews( parseInt(req.params.userId), typeof req.query.cursor === "string" ? parseInt(req.query.cursor) : 0 );
17+
res.status(StatusCodes.OK).success(reviews); }
18+
};
19+
```
20+
21+
- 수정
22+
23+
로그인한 사용자 id(req.user.id) 사용
24+
25+
```jsx
26+
export const handleListUserReviews = async (req, res, next) => {
27+
try {
28+
const userId = req.user.id;
29+
const cursor = typeof req.query.cursor === "string" ? parseInt(req.query.cursor) : 0;
30+
31+
const reviews = await listUserReviews(userId, cursor);
32+
33+
res.status(StatusCodes.OK).success(reviews);
34+
} catch (err) {
35+
next(err);
36+
}
37+
};
38+
```
39+
40+
41+
### 리뷰 추가 API, 가게의 미션을 도전 중인 미션에 추가 API
42+
43+
controller 수정
44+
45+
- 기존
46+
47+
```jsx
48+
try {
49+
const dto = createUserMissionDto(req.body);
50+
const userMission = await addUserMission(dto);
51+
res.status(StatusCodes.CREATED).success(userMission);
52+
} catch (err) {
53+
next(err);
54+
}
55+
```
56+
57+
- 수정
58+
59+
로그인한 사용자 id 사용
60+
61+
```jsx
62+
try {
63+
const dto = {
64+
...createUserMissionDto(req.body),
65+
userId: req.user.id,
66+
};
67+
68+
const userMission = await addUserMission(dto);
69+
res.status(StatusCodes.CREATED).success(userMission);
70+
} catch (err) {
71+
next(err);
72+
}
73+
```
74+
75+
76+
---
77+
78+
## 내 정보 수정 API
79+
80+
`PATCH /api/v1/users/my`
81+
82+
![스크린샷(293).png](https://github.com/user-attachments/assets/d642ef5b-5cad-4a08-880e-6dc80a268548)
83+
84+
성공 응답, 실패 응답(커스텀에러: 401로 처리)
85+
86+
![스크린샷(283).png](https://github.com/user-attachments/assets/2b98af66-8e6a-44ea-9f17-609782aebea8)
87+
88+
![스크린샷(284).png](https://github.com/user-attachments/assets/066b4c3d-00e1-49a7-b522-6c04cc8a5de2)
89+
90+
실행 결과
91+
92+
![스크린샷(282).png](https://github.com/user-attachments/assets/09178d86-8a60-4658-9a80-2fc00c952699)
93+
94+
![스크린샷(295).png](https://github.com/user-attachments/assets/9ee553ab-946d-499a-8185-09346e3e1119)
95+
96+
Postman GET /mypage 실행
97+
98+
내 정보 수정 API로 수정한 값으로 바뀐 것을 확인할 수 있다.
99+
100+
---
101+
102+
## 기존 APIJWT 적용하여 로그인한 사용자만 쓸 수 있도록 보호
103+
104+
### 미들웨어를 라우터에 적용
105+
106+
```jsx
107+
app.post("/api/v1/stores", isLogin, handleAddStore);
108+
...
109+
```
110+
111+
- isLogin 미들웨어를 로그인이 필요한 API 라우터에 적용 (`index.js`)
112+
113+
### swagger
114+
115+
![스크린샷(285).png](https://github.com/user-attachments/assets/89a4415d-92b4-436f-8f70-1d321247c37c)
116+
117+
```jsx
118+
const doc = {
119+
info: {
120+
title: "UMC 9th",
121+
description: "UMC 9th Node.js 테스트 프로젝트입니다.",
122+
},
123+
host: "localhost:3000",
124+
components: {
125+
securitySchemes: {
126+
BearerAuth: {
127+
type: "http",
128+
scheme: "bearer",
129+
bearerFormat: "JWT",
130+
},
131+
},
132+
},
133+
};
134+
```
135+
136+
- 기존 doc 객체에 `components.securitySchemes` 추가 (`index.js`)
137+
- 로그인이 필요한 API 주석에 `#swagger.security = [{ "BearerAuth": [] }]` 추가 (`controller.js`)

week10/keyword/keyword.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
- CI/CD
2+
3+
개발 → 빌드 → 테스트 → 배포 과정을 자동화하는 개발 프로세스
4+
5+
CI: 지속적 통합, 코드 변경 시 자동 빌드·테스트
6+
7+
CD: 지속적 배포, 테스트를 통과하면 자동으로 운영 환경 배포
8+
9+
- GitHub Actions
10+
11+
GitHub 내에서 CI/CD 파이프라인을 구성할 수 있는 워크플로우 자동화 도구
12+
13+
YAML 파일로 워크플로우 정의 (`.github/workflows/*.yml`)
14+
15+
GitHub에 내장되어 별도 CI 서버 불필요
16+
17+
- Reverse Proxy
18+
19+
클라이언트 요청을 받아 내부 서버로 전달하는 서버
20+
21+
클라이언트는 실제 서버 주소를 모름
22+
23+
로드 밸런싱: 여러 서버에 요청 분산
24+
25+
SSL 종료: HTTPS 요청 처리 후 내부 서버로 전달
26+
27+
캐싱: 정적 파일 캐싱 가능
28+
29+
보안: 서버 직접 노출 방지
30+
31+
- HTTPS
32+
33+
HTTP + TLS/SSL로 암호화된 통신 프로토콜
34+
35+
클라이언트 ↔ 서버 간 데이터 보호
36+
37+
암호화, 인증서 기반, 무결성

week10/mission/mission.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 미션 기록
2+
3+
### GitHub Actions 파이프라인 작성
4+
5+
![스크린샷(296).png](https://github.com/user-attachments/assets/5759a975-8de8-4ad8-b7dc-e8c30a074fed)
6+
7+
액션이 동작하도록 스크립트를 적은 후 main에 merge
8+
9+
원격접속 후 터미널에서 명령어로 패키지 설치 중인데 설치가 중간에 멈춘 상황..

0 commit comments

Comments
 (0)