- 경기 맥락(전날 결과·순위·연전 차수·선발투수) 조립 → LLM 작사 (콜앤리스폰스·섹션 태그 형식) → Suno(sunoapi.org) 생성 → songs 테이블 - 워커: 킥오프 150분 전 윈도우 진입 시 생성 시작 + 2분 주기 폴링 - API: GET /api/songs/today · POST /api/songs/callback(싱크대) · POST /api/songs/generate(관리자 강제 생성) - 프론트: MusicBar 가 경기 상세·메인에서 오늘의 응원가를 동적 로드 (정적 플레이리스트는 폴백 유지) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
"""FastAPI 앱 진입점 — API 서버.
|
|
|
|
시작 시 DB 초기화 + 시드. CORS 허용. 라우터 등록.
|
|
스케줄러는 별도 워커 컨테이너(worker.py)에서 실행한다(중복 방지).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .config import settings
|
|
from .database import init_db
|
|
from .routers import (
|
|
admin,
|
|
auth,
|
|
comments,
|
|
leaderboard,
|
|
matches,
|
|
predictions,
|
|
share,
|
|
songs,
|
|
standings,
|
|
visits,
|
|
)
|
|
from .scoring import load_scoring_data
|
|
from .seed import seed_if_empty
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
log = logging.getLogger("triplepick")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI): # noqa: ANN201
|
|
load_scoring_data() # data/scoring.json → 배점·배제 대상
|
|
await init_db()
|
|
await seed_if_empty()
|
|
log.info("API ready")
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="TriplePick API", version="1.0.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origin_list,
|
|
allow_credentials=False,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(matches.router)
|
|
app.include_router(comments.router)
|
|
app.include_router(predictions.router)
|
|
app.include_router(leaderboard.router)
|
|
app.include_router(standings.router)
|
|
app.include_router(admin.router)
|
|
app.include_router(visits.router)
|
|
app.include_router(songs.router)
|
|
# 공유 미리보기(OG) 프리렌더 — nginx 가 크롤러 UA 의 /match/:id 만 여기로 보낸다.
|
|
app.include_router(share.router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health() -> dict:
|
|
return {"ok": True, "service": "triplepick-api"}
|