65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
"""FastAPI application entry point.
|
|
|
|
Configures CORS, registers routers under /api/v1, exposes health endpoint.
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import APIRouter, FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import settings
|
|
from app.routers import auth, contacts, copilot, datev, files, ocr, sales, users, vehicles
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application startup and shutdown lifecycle."""
|
|
# Startup: could run alembic migrations here in production
|
|
yield
|
|
# Shutdown: cleanup resources
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.APP_NAME,
|
|
description="ERP Nutzfahrzeuge Backend API",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# CORS configuration from settings
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins_list,
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# API v1 router
|
|
api_v1_router = APIRouter(prefix="/api/v1")
|
|
api_v1_router.include_router(auth.router)
|
|
api_v1_router.include_router(users.router)
|
|
api_v1_router.include_router(vehicles.router)
|
|
api_v1_router.include_router(contacts.router)
|
|
api_v1_router.include_router(files.router)
|
|
api_v1_router.include_router(ocr.router)
|
|
api_v1_router.include_router(sales.router)
|
|
api_v1_router.include_router(datev.router)
|
|
api_v1_router.include_router(copilot.router)
|
|
|
|
# Health endpoint (no auth required)
|
|
@api_v1_router.get("/health", tags=["health"])
|
|
async def health_check():
|
|
"""Health check endpoint."""
|
|
return {"status": "ok"}
|
|
|
|
|
|
app.include_router(api_v1_router)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""Root redirect info."""
|
|
return {"name": settings.APP_NAME, "version": "1.0.0", "docs": "/docs"}
|