Initial commit

This commit is contained in:
2026-05-29 08:11:07 +09:00
commit 9d192c430d
824 changed files with 575587 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
"""
FastAPI 백엔드 API 서버
- /api/hello: Vue 프론트엔드에서 호출할 JSON API 엔드포인트
- / (static): 빌드된 Vue SPA 정적 파일 서빙
실행:
uvicorn app:app --reload --port 8000
"""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from database import engine
from models import Base
from routers.samples import router as samples_router
@asynccontextmanager
async def lifespan(app: FastAPI):
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield
app = FastAPI(title="Hello Web API", lifespan=lifespan)
# CORS 설정 - Vue 개발 서버(localhost:5173)의 요청을 허용
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(samples_router)
# JSON API 엔드포인트
@app.get("/api/hello")
async def hello_api():
"""
Vue 프론트엔드가 호출할 API 엔드포인트.
Returns:
dict: 메시지와 초기 카운트 값을 JSON 형태로 반환
"""
return {
"message": "Hello from FastAPI!",
"initialCount": 0,
}
# Vue 빌드 결과물(정적 파일) 서빙
# frontend/dist 폴더를 정적 파일 디렉토리로 마운트
app.mount("/", StaticFiles(directory="../frontend/dist", html=True), name="frontend")