This repository has been archived on 2026-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

59 lines
1.8 KiB
Python

import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy import create_engine, text
from . import models
from .config import settings
from .database import Base, engine
from .routers import admin, auth, instances, templates
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s %(message)s",
)
logger = logging.getLogger(__name__)
app = FastAPI(
title="Proxmox VPS Panel Secure",
version="1.2.0",
)
origins = [item.strip() for item in settings.allow_origins.split(",") if item.strip()]
if not origins:
raise RuntimeError("ALLOW_ORIGINS must contain at least one explicit origin")
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
allow_headers=["Authorization", "Content-Type"],
)
# Временное создание таблиц до добавления Alembic-миграций.
Base.metadata.create_all(bind=engine)
app.include_router(auth.router)
app.include_router(admin.router)
app.include_router(templates.router)
app.include_router(instances.router)
@app.get("/health")
def health() -> dict[str, str]:
"""Проверяет, что процесс приложения запущен."""
return {"status": "ok"}
@app.get("/health/ready")
def readiness() -> dict[str, str]:
"""Проверяет доступность критичной зависимости PostgreSQL."""
check_engine = create_engine(settings.database_url, pool_pre_ping=True)
try:
with check_engine.connect() as connection:
connection.execute(text("SELECT 1"))
finally:
check_engine.dispose()
return {"status": "ready"}