Skip to content

Commit 534a602

Browse files
authored
fix: 배포 환경에서 API 주소 오류 수정 (#211)
* feat: 작품 둘러보기 api 연결 및 구현 완료 * feat: 작품 둘러보기 주소 변경 * fix: 배포 환경에서 API 주소 오류 수정
1 parent 0c2f067 commit 534a602

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/api/user/postListApi.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import axios from "axios";
22
import Cookies from "js-cookie";
33
import { StringOptionsWithImporter } from "sass";
44

5-
const apiUrl = import.meta.env.VITE_API_URL;
5+
import { SERVER_URL } from "@/constants/ServerURL";
66

77
const api = axios.create({
8-
baseURL: apiUrl, // Use environment variables
8+
baseURL: SERVER_URL, // Use environment variables
9+
910
timeout: 10000,
1011
});
1112

@@ -45,8 +46,15 @@ export const fetchExploreScripts = async (
4546
withCredentials: true, // 쿠키 인증 시 필요
4647
});
4748

48-
console.log(response);
49-
return response.data;
49+
50+
const { longPlay, shortPlay } = response.data;
51+
console.log(longPlay);
52+
console.log(shortPlay);
53+
return {
54+
longPlay: Array.isArray(longPlay) ? longPlay : [],
55+
shortPlay: Array.isArray(shortPlay) ? shortPlay : [],
56+
};
57+
5058
} catch (error) {
5159
console.error("Error fetchExploreScripts:", error);
5260
throw new Error(`작품 둘러보기 API 호출 실패: ${(error as Error).message}`);

src/pages/work/postList/PostGallery.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ const PostGallery = () => {
3737
try {
3838
const accessToken = Cookies.get("accessToken");
3939
const data = await fetchExploreScripts(accessToken);
40-
setLongPlays(data.longPlay);
41-
setShortPlays(data.shortPlay);
40+
41+
setLongPlays(Array.isArray(data.longPlay) ? data.longPlay : []);
42+
setShortPlays(Array.isArray(data.shortPlay) ? data.shortPlay : []);
43+
4244
} catch (error) {
4345
console.error("작품 목록 불러오기 실패:", error);
4446
} finally {
@@ -48,7 +50,9 @@ const PostGallery = () => {
4850
loadScripts();
4951
}, []);
5052

51-
const sortPosts = (posts: ScriptItem[], sortType: string) => {
53+
54+
const sortPosts = (posts: ScriptItem[] = [], sortType: string) => {
55+
5256
const sorted = [...posts]; // 원본 배열 복사
5357
switch (sortType) {
5458
case "조회수순":

0 commit comments

Comments
 (0)