统一对话页与供应商画像的采购订单、异常数、基础分、频次系数、供应商得分和层级计算;补充供应商维度计算结果字段,保留未归类品类标记并优化供应商列表聚合查询;增加响应压缩并完善供应商统计测试。
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""FastAPI application factory."""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from starlette.middleware.gzip import GZipMiddleware
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import Settings, get_settings
|
|
from app.core.exceptions import AppException, app_exception_handler
|
|
from app.core.logging import configure_logging
|
|
|
|
|
|
def create_app(settings: Settings | None = None) -> FastAPI:
|
|
resolved_settings = settings or get_settings()
|
|
configure_logging(resolved_settings.log_level)
|
|
|
|
application = FastAPI(
|
|
title=resolved_settings.app_name,
|
|
version=resolved_settings.app_version,
|
|
debug=resolved_settings.debug,
|
|
)
|
|
application.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=list(resolved_settings.cors_allow_origins),
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PATCH", "DELETE", "OPTIONS"],
|
|
allow_headers=["Authorization", "Content-Type", "Accept"],
|
|
)
|
|
application.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)
|
|
application.add_exception_handler(AppException, app_exception_handler)
|
|
application.include_router(api_router)
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
|