diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..ef24a3a --- /dev/null +++ b/backend/main.py @@ -0,0 +1,41 @@ +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse +from pathlib import Path + +# Импорт роутера +from .routes.license_routes import router as license_router # Изменено: один dot вместо двух + +# Путь к корню проекта +BASE_DIR = Path(__file__).resolve().parent + +def create_app() -> FastAPI: + """ + Создание и конфигурация FastAPI приложения. + Подключает роутеры и статические файлы. + """ + apps: FastAPI = FastAPI( + title="License Generator API", + description="API для генерации лицензий Custom.mxtpro", + version="1.0.0" + ) + + # Подключение роутеров + apps.include_router(license_router, prefix="/api") + + # Монтируем статические папки фронтенда + apps.mount("/static/css", StaticFiles(directory=BASE_DIR.parent / "frontend" / "css"), name="css") + apps.mount("/static/js", StaticFiles(directory=BASE_DIR.parent / "frontend" / "js"), name="js") + apps.mount("/static/assets", StaticFiles(directory=BASE_DIR.parent / "frontend" / "assets"), name="assets") + + # Отдача главной страницы + @apps.get("/", include_in_schema=False) + def read_index() -> FileResponse: + """ + Отдает главную страницу сайта (index.html) + """ + return FileResponse(BASE_DIR.parent / "frontend" / "templates" / "index.html") + return apps + +# Экземпляр приложения +app: FastAPI = create_app()