File size: 1,197 Bytes
7a88b43 cb2a233 7a88b43 cb2a233 7a88b43 cb2a233 7a88b43 cb2a233 7a88b43 cb2a233 7a88b43 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
"""Main FastAPI app instance declaration."""
import fastapi
from fastapi.middleware.cors import CORSMiddleware
import structlog
import uvicorn
from app.core.config import settings
from .core.middlewares import add_middlewares
from app.router import api_router
# Set up structlog for logging
logger = structlog.get_logger()
# Create FastAPI app with explicit paths
fastapi_app = fastapi.FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
description=settings.DESCRIPTION,
openapi_url="/openapi.json", # Explicit path
docs_url="/docs", # Explicit path
redoc_url="/redoc", # Explicit path
)
# Add CORS middleware directly
fastapi_app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
fastapi_app.include_router(api_router)
add_middlewares(fastapi_app)
# Log the app startup
logger.info(
"Application started", project=settings.PROJECT_NAME, version=settings.VERSION
)
if __name__ == "__main__":
uvicorn.run(
"main:fastapi_app",
host=settings.UVICORN_HOST,
port=settings.UVICORN_PORT,
reload=True,
)
|