Files
Proxmox-VPS-Panel/backend/app/main.py
T
2026-07-25 03:27:16 +03:00

59 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import logging
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from . import models
from .database import engine
from .routers import auth, templates, instances, admin
# Структурированное логирование: единый формат для контейнера.
logging.basicConfig(
level=os.getenv("LOG_LEVEL", "INFO"),
format="%(asctime)s %(levelname)s %(name)s [%(filename)s:%(lineno)d] %(message)s",
)
logger = logging.getLogger("panel")
models.Base.metadata.create_all(bind=engine)
app = FastAPI(
title="Proxmox VPS Panel",
version="0.3.0",
description="Self-hosted панель для управления VPS на Proxmox VE.",
)
# CORS: список доменов через переменную окружения ALLOW_ORIGINS (через запятую).
_origins_raw = os.getenv("ALLOW_ORIGINS", "http://localhost:5173,http://127.0.0.1:5173")
allow_origins = [o.strip() for o in _origins_raw.split(",") if o.strip()]
if "*" in allow_origins:
logger.warning(
"ALLOW_ORIGINS='*' — небезопасно для прода и не работает с allow_credentials=True. "
"Укажите конкретные домены."
)
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
allow_headers=["Authorization", "Content-Type"],
)
app.include_router(auth.router)
app.include_router(templates.router)
app.include_router(instances.router)
app.include_router(admin.router)
@app.get("/health")
def health():
"""Healthcheck — приложение живо."""
return {"status": "ok"}
@app.get("/health/ready")
def readiness():
"""Readiness — готов к приёму трафика."""
return {"status": "ready"}