43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import get_settings
|
|
from app.core.errors import register_exception_handlers
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
settings = get_settings()
|
|
app = FastAPI(
|
|
title="Desi Clans API",
|
|
version="0.2.0",
|
|
debug=settings.environment.lower() == "development",
|
|
)
|
|
|
|
register_exception_handlers(app)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origin_list,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
if settings.storage_backend.lower() == "local":
|
|
upload_path = Path(settings.upload_dir)
|
|
upload_path.mkdir(parents=True, exist_ok=True)
|
|
app.mount("/media", StaticFiles(directory=str(upload_path)), name="media")
|
|
|
|
if settings.environment.lower() == "production":
|
|
app.openapi_url = None
|
|
|
|
app.include_router(api_router, prefix="/api")
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|