-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
116 lines (100 loc) · 3.58 KB
/
Copy pathmain.py
File metadata and controls
116 lines (100 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import uvicorn
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
# -------------------------------------------------------
# [Routers] API 라우터 임포트
# -------------------------------------------------------
# 본인이 개발한 라우터
from src.app.routers import history_api
from src.app.routers import library_api
from src.app.routers import auth
from src.app.routers import search
from src.app.routers import panel_api
# -------------------------------------------------------
# [App] FastAPI 앱 초기화
# -------------------------------------------------------
app = FastAPI(
title="All is Well API Server",
description="사용자 의도 파악 기반 패널 검색 시스템",
version="2.0.0",
docs_url="/docs", # Swagger UI
redoc_url="/redoc" # ReDoc
)
# -------------------------------------------------------
# [CORS] 프론트엔드 연동 설정 (가장 중요!)
# -------------------------------------------------------
origins = [
"http://localhost:5173", # Vite 개발 서버 (Localhost)
"http://127.0.0.1:5173", # Vite 개발 서버 (IP)
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins, # 허용할 출처 목록
allow_credentials=True, # 쿠키/인증 헤더 허용 (로그인 기능 필수)
allow_methods=["*"], # 모든 HTTP 메서드 허용 (GET, POST, PUT, DELETE...)
allow_headers=["*"], # 모든 헤더 허용
)
# -------------------------------------------------------
# [Static] 정적 파일 서빙 (이미지 등)
# -------------------------------------------------------
# static 폴더가 없으면 자동 생성
if not os.path.exists("static"):
os.makedirs("static")
# http://localhost:8000/static/... 으로 접근 가능
app.mount("/static", StaticFiles(directory="static"), name="static")
# -------------------------------------------------------
# [Routers] 라우터 등록
# -------------------------------------------------------
print("--- 🚀 API 라우터 등록 시작 ---")
# 1. Auth (인증)
app.include_router(
auth.router,
prefix="/api" # auth.py 내부 prefix="/auth"와 결합됨
)
print(" ✅ Auth Router Registered")
# 2. Search (검색)
app.include_router(
search.router,
prefix="/api" # search.py 내부 prefix="/search"와 결합됨
)
print(" ✅ Search Router Registered")
# 3. Panel (패널 상세)
app.include_router(panel_api.router, prefix="/api")
print(" ✅ Panel Router Registered")
# 4. History (검색 기록)
app.include_router(
history_api.router,
prefix="/api" # history_api.py 내부 prefix="/history"와 결합됨
)
print(" ✅ History Router Registered")
# 5. Library (라이브러리)
app.include_router(
library_api.router,
prefix="/api"
)
print(" ✅ Library Router Registered")
print("--- ✨ 모든 API 라우터 등록 완료 ---")
# -------------------------------------------------------
# [Root] 헬스 체크
# -------------------------------------------------------
@app.get("/")
async def root():
return {
"message": "All is Well API Server is Running! 🚀",
"docs": "http://localhost:5000/docs",
"version": "v2.0.0"
}
# -------------------------------------------------------
# [Main] 실행 진입점
# -------------------------------------------------------
if __name__ == "__main__":
# 개발 환경: Auto Reload 활성화
# 배포 환경에서는 reload=False로 설정해야 함
uvicorn.run(
"main:app",
host="127.0.0.1",
port=5001,
reload=True
)