Skip to content

Commit bce0ff9

Browse files
committed
Feat : 폴더 생성 기능 구현
1 parent 24e3b97 commit bce0ff9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/api/axiosInstanceApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const axiosInstance = axios.create({
88

99
export const proxy = axios.create({
1010
// 배포 이후에는 배포된 URL로 변경해야 함.
11-
// baseURL: "http://localhost:3000", -> baseURL을 안쓰면 로컬에서는 로컬3000, 배포했을때는 배포된 도메인으로 감
11+
baseURL: "http://localhost:3000",
1212
timeout: 5000,
1313
withCredentials: true,
1414
});

pages/api/folders/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axiosInstance from "@/lib/api/axiosInstanceApi";
2+
import axios from "axios";
23
import { NextApiRequest, NextApiResponse } from "next";
34

45
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
@@ -11,13 +12,19 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
1112

1213
if (req.method === "POST") {
1314
try {
14-
const { name } = req.body;
15-
16-
const response = await axiosInstance.post("/folders", { name });
15+
const response = await axiosInstance.post("/folders", req.body, {
16+
headers: {
17+
Authorization: `Bearer ${token}`,
18+
},
19+
});
1720
console.log(response);
1821
return res.status(200).json({ message: "폴더 생성 성공" });
1922
} catch (error) {
20-
return res.status(500).json({ message: "서버 오류" });
23+
if (axios.isAxiosError(error) && error.response) {
24+
const status = error.response.status;
25+
const message = error.response.data?.message || "알 수 없는 오류 발생";
26+
return res.status(status).json({ message });
27+
}
2128
}
2229
} else {
2330
res.status(405).json({ message: "허용되지 않은 접근 방법" });

0 commit comments

Comments
 (0)