44 lines
1 KiB
Python
44 lines
1 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.middleware.auth import AuthMiddleware
|
|
from app.routers import auth, devices, objects, tags
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Startup: future workers (monitor, stale task recovery) will be launched here in Этап 2+
|
|
yield
|
|
# Shutdown
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title="Fleet Manager",
|
|
description="Centralized device fleet management service",
|
|
version="0.1.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.add_middleware(AuthMiddleware)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(objects.router)
|
|
app.include_router(devices.router)
|
|
app.include_router(tags.router)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|