Files
zebra-power/backend/app/main.py

47 lines
1.5 KiB
Python

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from app.database import init_db
from app.api import wol, hosts
import traceback
app = FastAPI(title="Zebra Power", description="Wake-on-LAN and Proxmox Management API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
return JSONResponse(
status_code=500,
content={"detail": f"Internal server error: {str(exc)}"},
headers={
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
}
)
# Anciens endpoints conservés temporairement pour transition
# app.include_router(servers.router, prefix="/api/servers", tags=["servers"]) - SUPPRIMÉ
# app.include_router(proxmox.router, prefix="/api/proxmox", tags=["proxmox"]) - SUPPRIMÉ
app.include_router(wol.router, prefix="/api/wol", tags=["wol"]) # Conservé pour les logs
app.include_router(hosts.router, prefix="/api/hosts", tags=["hosts"]) # Nouvelle API unifiée
@app.on_event("startup")
async def startup_event():
init_db()
@app.get("/")
async def root():
return {"message": "Zebra Power API is running"}
@app.get("/api/health")
async def health_check():
return {"status": "healthy"}