File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,11 @@ import axios from "axios";
22import Cookies from "js-cookie" ;
33import { StringOptionsWithImporter } from "sass" ;
44
5- const apiUrl = import . meta . env . VITE_API_URL ;
5+ import { SERVER_URL } from "@/constants/ServerURL" ;
66
77const 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 } ` ) ;
Original file line number Diff line number Diff 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 "조회수순" :
You can’t perform that action at this time.
0 commit comments