Skip to content

Commit 8d2720e

Browse files
committed
Feat: s3 채팅방 이미지 업로드
1 parent aa64524 commit 8d2720e

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
VITE_CORE_FRONT_BASE_URL="http://localhost:5173"
2-
VITE_CORE_API_BASE_URL="http://localhost:8090"
2+
VITE_CORE_API_BASE_URL="http://localhost:8090"
3+
REACT_APP_API_URL=http://localhost:8090

src/components/ChatRoomList.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ChatService from '../services/ChatService';
44
import ChatRoom from './ChatRoom';
55
import PasswordModal from './PasswordModal';
66
import './ChatStyles.css';
7-
import { API_BACKEND_URL } from '../config';
87
import { Home } from 'lucide-react'; // Import Home icon from lucide-react
98

109
const ChatRoomList = () => {
@@ -263,13 +262,16 @@ const ChatRoomList = () => {
263262
const isRoomsEmpty = rooms.length === 0;
264263

265264
const getImageUrl = (imageUrl) => {
266-
if (!imageUrl) return null;
267-
console.log('Original imageUrl:', imageUrl); // 디버깅용
268-
// API_BACKEND_URL이 이미 슬래시로 끝나지 않는지 확인
269-
const baseUrl = API_BACKEND_URL.endsWith('/') ? API_BACKEND_URL.slice(0, -1) : API_BACKEND_URL;
270-
const fullUrl = `${baseUrl}${imageUrl}`;
271-
console.log('Full imageUrl:', fullUrl); // 디버깅용
272-
return fullUrl;
265+
if (!imageUrl) return '/default-room.png';
266+
try {
267+
// 이미 완전한 S3 URL인 경우 그대로 반환
268+
if (imageUrl.includes('s3.ap-northeast-2.amazonaws.com')) {
269+
return imageUrl;
270+
}
271+
return '/default-room.png';
272+
} catch {
273+
return '/default-room.png';
274+
}
273275
};
274276

275277
return (
@@ -345,10 +347,13 @@ const ChatRoomList = () => {
345347
src={getImageUrl(room.imageUrl)}
346348
alt={room.title}
347349
className="room-image"
350+
loading="lazy"
348351
onError={(e) => {
349-
console.log('Image load failed:', room.imageUrl);
350-
e.target.onerror = null;
351-
e.target.src = '/default-room.png';
352+
if (!e.target.getAttribute('data-error-handled')) {
353+
console.error('Image load failed:', room.imageUrl);
354+
e.target.setAttribute('data-error-handled', 'true');
355+
e.target.src = '/default-room.png';
356+
}
352357
}}
353358
/>
354359
) : (

src/config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const API_BACKEND_URL = import.meta.env.VITE_CORE_API_BASE_URL;
2-
const API_FRONT_URL = import.meta.env.VITE_CORE_FRONT_BASE_URL;
1+
// Vite 환경변수 사용
2+
const API_BACKEND_URL = import.meta.env.VITE_CORE_API_BASE_URL || 'http://localhost:8090';
3+
const API_FRONT_URL = import.meta.env.VITE_CORE_FRONT_BASE_URL || 'http://localhost:5173';
34

4-
export { API_BACKEND_URL, API_FRONT_URL };
5+
export {
6+
API_BACKEND_URL,
7+
API_FRONT_URL
8+
};

0 commit comments

Comments
 (0)