32 lines
952 B
Python
32 lines
952 B
Python
from fastapi import FastAPI
|
|
from starlette.staticfiles import StaticFiles
|
|
from contextlib import asynccontextmanager
|
|
from backend.repository.db_init import Base, engine
|
|
from backend.routers.game_router import router as game_router
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
print("서버 시작")
|
|
|
|
# Base 에 등록된 모든 모델에 테이블 자동 생성
|
|
Base.metadata.create_all(bind=engine)
|
|
print("[DB] 테이블 생성 완료 (또는 이미 존재)")
|
|
|
|
yield
|
|
print("서버 종료")
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
app = FastAPI(title="로그라이크 AI 백엔드", version="1.0", lifespan=lifespan)
|
|
|
|
# 같은 네트워크 상의 모든 외부 기기(PC, 폰 등) 브라우저 접속 허용
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 라우터 등록
|
|
app.include_router(game_router) |