✅ feature/front-end → main (완료)
✅ chatbot → main (완료)
✅ 리모트 push 완료
Frontend (React) Backend Options
↓ ↓
📱 localhost:3000 → 🔀 localhost:3001
├── 🟦 Mock Server (Node.js)
└── 🟩 Flask Server (Python)
옵션 1: 포트 분리
- Mock Server: 포트 3001
- Flask Server: 포트 3002
옵션 2: 환경별 분리
- 개발환경: Mock Server (3001)
- 운영환경: Flask Server (3001)
- Base URL:
http://localhost:3001/api - Content-Type:
application/json - CORS: 활성화
POST /api/chat/send요청
{
"userId": "string (required)",
"threadNum": "string (required)",
"content": "string (required)",
"timestamp": "string (required)"
}응답 (성공)
{
"userId": "string",
"threadNum": "string",
"timestamp": "string",
"status": "completed|pending",
"content": "string",
"quote": {
"id": "string",
"text": "string",
"author": "string",
"category": "string"
} // 4단계 완료 시에만 포함
}GET /api/chat/status?userId={userId}&threadNum={threadNum}응답
{
"userId": "string",
"threadNum": "string",
"timestamp": "string",
"status": "completed|pending|error",
"content": "string",
"quote": object | null
}GET /api/chat/stream?userId={userId}&threadNum={threadNum}응답 (Server-Sent Events)
data: {"type": "message", "content": "응답 텍스트"}
data: {"type": "quote", "quote": {...}}
data: {"type": "complete"}
GET /api/health응답
{
"status": "OK",
"timestamp": "string",
"activeConversations": number
}// 환경 설정
const API_CONFIG = {
baseUrl: process.env.REACT_APP_API_BASE_URL || "http://localhost:3001/api",
pollingInterval: 3000,
enableStreaming: process.env.REACT_APP_ENABLE_STREAMING === "true"
};
// 메시지 전송
export const sendMessage = async (request: ChatRequest): Promise<ChatResponse>
// 상태 폴링
export const pollStatus = (userId, threadNum, onUpdate, onError): () => void
// 스트리밍 연결
export const createStreamingConnection = (userId, threadNum, onChunk, onError, onComplete): () => void// 1. 메시지 전송
const response = await sendMessage({
userId: "user123",
threadNum: "thread001",
content: "안녕하세요",
timestamp: new Date().toISOString(),
});
// 2. 폴링 시작
const stopPolling = pollStatus(
"user123",
"thread001",
(response) => console.log("업데이트:", response),
(error) => console.error("에러:", error)
);1단계: 사용자 메시지 → 봇 응답 (감정 파악)
2단계: 사용자 메시지 → 봇 응답 (상세 질문)
3단계: 사용자 메시지 → 봇 응답 (공감 표현)
4단계: 사용자 메시지 → 봇 응답 + 맞춤 명언 ✨
- pending: 처리 중
- completed: 완료 (응답 포함)
- error: 오류 발생
npm run dev # React + Mock Server 동시 실행# 백엔드
python app.py
# 프론트엔드
npm startREACT_APP_API_BASE_URL=http://localhost:3001/api
REACT_APP_ENABLE_STREAMING=false- React: 3000
- Mock Server: 3001
- Flask Server: 3002 (권장)
- 프론트엔드 → 백엔드 통신 정상
- CORS 설정 완료
- 에러 처리 구현
- 폴링/스트리밍 동작 확인
- 4단계 대화 플로우 테스트
- 명언 생성 로직 검증
- 포트 충돌 해결 (Mock: 3001, Flask: 3002)
- 환경별 설정 분리 (개발/운영)
- API 응답 시간 최적화
- 에러 처리 강화
- 로그 시스템 구축
API 연동 관련 문제나 질문이 있으시면 언제든 연락주세요! 🚀