78 lines
1.9 KiB
Python
78 lines
1.9 KiB
Python
"""
|
|
FastAPI 애플리케이션 진입점
|
|
- 태양광 발전 관제 시스템 미들웨어 서버
|
|
"""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.core.config import get_settings
|
|
from app.routers import plants, upload, stats
|
|
|
|
# 설정 로드
|
|
settings = get_settings()
|
|
|
|
# FastAPI 앱 생성
|
|
app = FastAPI(
|
|
title=settings.APP_NAME,
|
|
version=settings.APP_VERSION,
|
|
description="태양광 발전 관제 시스템을 위한 미들웨어 API 서버",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# CORS 미들웨어 설정 (모든 도메인 허용 - 개발용)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 라우터 등록 (순서 중요: 더 구체적인 경로를 먼저 등록)
|
|
app.include_router(stats.router) # /plants/{plant_id}/stats
|
|
app.include_router(upload.router) # /plants/{plant_id}/upload
|
|
app.include_router(plants.router) # /plants/{company_id} (가장 일반적인 경로)
|
|
|
|
|
|
@app.get("/", tags=["Health"])
|
|
async def health_check() -> dict:
|
|
"""
|
|
서버 상태 확인 (Health Check)
|
|
|
|
Returns:
|
|
서버 상태 및 버전 정보
|
|
"""
|
|
return {
|
|
"status": "healthy",
|
|
"app_name": settings.APP_NAME,
|
|
"version": settings.APP_VERSION
|
|
}
|
|
|
|
|
|
@app.get("/health", tags=["Health"])
|
|
async def detailed_health_check() -> dict:
|
|
"""
|
|
상세 서버 상태 확인
|
|
|
|
Returns:
|
|
서버 상태 및 연결 정보
|
|
"""
|
|
return {
|
|
"status": "healthy",
|
|
"app_name": settings.APP_NAME,
|
|
"version": settings.APP_VERSION,
|
|
"supabase_connected": bool(settings.SUPABASE_URL)
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(
|
|
"app.main:app",
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
reload=settings.DEBUG
|
|
)
|