41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""Создание FastAPI-приложения админки."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from admin.routes import health, pages
|
|
from common import __version__
|
|
from common.config import AdminSettings, get_admin_settings
|
|
from common.logging_config import setup_logging
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent
|
|
TEMPLATES_DIR = BASE_DIR / "templates"
|
|
|
|
|
|
def create_app(settings: AdminSettings | None = None) -> FastAPI:
|
|
"""Собрать приложение: настройки, шаблоны, роутеры.
|
|
|
|
Настройки можно передать явно (тесты); по умолчанию читаются из окружения.
|
|
"""
|
|
setup_logging()
|
|
settings = settings or get_admin_settings()
|
|
|
|
app = FastAPI(
|
|
title="DispelEvilBot Admin",
|
|
version=__version__,
|
|
# Swagger/OpenAPI наружу пока не нужны: админка закрыта логином (Блок 4.2).
|
|
docs_url=None,
|
|
redoc_url=None,
|
|
openapi_url=None,
|
|
)
|
|
app.state.settings = settings
|
|
app.state.templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(pages.router)
|
|
return app
|