Skip to content

Commit d2fcfcf

Browse files
committed
fix: 커뮤니티 페이지 API 프록시 누락 수정 + 방어 코드 추가
- next.config.js: catch-all → scoped proxy 전환 시 누락된 경로 추가 (articles, auth, profile, universities, matching) - community/page.tsx: API 응답 Array.isArray() 방어 코드 추가
1 parent 6bb2b84 commit d2fcfcf

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

app/community/page.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default function Community() {
188188
setPosts(postsWithComments);
189189
};
190190

191-
if (posts.length > 0) {
191+
if (Array.isArray(posts) && posts.length > 0) {
192192
loadComments();
193193
}
194194
}, [posts.length]);
@@ -212,7 +212,9 @@ export default function Community() {
212212
},
213213
});
214214

215-
const newPosts = response.data.items;
215+
const newPosts = Array.isArray(response.data?.items)
216+
? response.data.items
217+
: [];
216218

217219
// 첫 페이지면 기존 데이터 교체, 아니면 추가
218220
if (page === 1) {
@@ -739,21 +741,22 @@ export default function Community() {
739741
Authorization: `Bearer ${token}`,
740742
},
741743
});
744+
const comments = Array.isArray(response.data) ? response.data : [];
742745
// 댓글 목록을 받아온 후 바로 상태 업데이트
743746
setPosts((prevPosts) => {
744747
const updatedPosts = prevPosts.map((post) => {
745748
if (post.id === postId) {
746749
return {
747750
...post,
748-
comments: response.data,
751+
comments,
749752
};
750753
}
751754
return post;
752755
});
753756
return updatedPosts;
754757
});
755758

756-
return response.data;
759+
return comments;
757760
} catch (error) {
758761
console.error("댓글 조회 중 오류가 발생했습니다:", error);
759762
return [];

next.config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@ const nextConfig = {
3434
{ source: '/api-proxy/admin/:path*', destination: `${backendUrl}/admin/:path*` },
3535
// Support chat admin calls
3636
{ source: '/api-proxy/support-chat/:path*', destination: `${backendUrl}/support-chat/:path*` },
37-
// User auth and profile calls
38-
{ source: '/api-proxy/auth/login', destination: `${backendUrl}/auth/login` },
39-
{ source: '/api-proxy/auth/refresh', destination: `${backendUrl}/auth/refresh` },
37+
// Community article calls
38+
{ source: '/api-proxy/articles/:path*', destination: `${backendUrl}/articles/:path*` },
39+
{ source: '/api-proxy/articles', destination: `${backendUrl}/articles` },
40+
// Auth calls
41+
{ source: '/api-proxy/auth/:path*', destination: `${backendUrl}/auth/:path*` },
42+
// Profile calls
43+
{ source: '/api-proxy/profile/:path*', destination: `${backendUrl}/profile/:path*` },
4044
{ source: '/api-proxy/profile', destination: `${backendUrl}/profile` },
45+
// University calls
46+
{ source: '/api-proxy/universities/:path*', destination: `${backendUrl}/universities/:path*` },
47+
{ source: '/api-proxy/universities', destination: `${backendUrl}/universities` },
48+
// Matching calls
49+
{ source: '/api-proxy/matching/:path*', destination: `${backendUrl}/matching/:path*` },
50+
{ source: '/api-proxy/matching', destination: `${backendUrl}/matching` },
4151
{ source: '/api/admin/rematch-request', destination: `${backendUrl}/admin/matching/rematch-request` },
4252
{ source: '/api/notifications/:path*', destination: `${backendUrl}/notifications/:path*` },
4353
{ source: '/api/notifications', destination: `${backendUrl}/notifications` },

0 commit comments

Comments
 (0)