- Add main application files (main.py, models.py, schemas.py, etc.) - Add routers for all features (waiting, attendance, members, etc.) - Add HTML templates for admin and user interfaces - Add migration scripts and utility files - Add Docker configuration - Add documentation files - Add .gitignore to exclude database and cache files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from fastapi import APIRouter
|
|
from fastapi.responses import StreamingResponse
|
|
from sse_manager import sse_manager, event_generator
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/stream")
|
|
async def sse_stream(store_id: str):
|
|
"""
|
|
SSE 스트림 엔드포인트
|
|
- 매장별로 실시간 이벤트를 수신
|
|
- 클라이언트는 EventSource로 연결
|
|
- Query parameter: store_id
|
|
"""
|
|
# 새로운 연결 등록
|
|
print(f"[SSE] Connection Request: store_id={store_id}")
|
|
queue = await sse_manager.connect(store_id)
|
|
|
|
async def cleanup():
|
|
"""연결 종료 시 정리"""
|
|
sse_manager.disconnect(store_id, queue)
|
|
|
|
# SSE 응답 생성
|
|
response = StreamingResponse(
|
|
event_generator(queue),
|
|
media_type="text/event-stream",
|
|
headers={
|
|
"Cache-Control": "no-cache",
|
|
"Connection": "keep-alive",
|
|
"X-Accel-Buffering": "no", # Nginx 버퍼링 비활성화
|
|
}
|
|
)
|
|
|
|
# 연결 종료 시 cleanup 호출하도록 설정
|
|
response.background = cleanup
|
|
|
|
return response
|