- 将估值计算改为后台任务执行,提高响应速度 - 添加估值评估记录的软删除功能 - 更新评估状态字段值从approved/rejected改为success/fail - 修复注册接口的HTTP状态码问题 - 更新API版本号和服务器配置 - 禁用FastAPI尾部斜杠重定向
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from tortoise import Tortoise
|
|
|
|
from app.core.exceptions import SettingNotFound
|
|
from app.core.init_app import (
|
|
init_data,
|
|
make_middlewares,
|
|
register_exceptions,
|
|
register_routers,
|
|
)
|
|
|
|
try:
|
|
from app.settings.config import settings
|
|
except ImportError:
|
|
raise SettingNotFound("Can not import settings")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await init_data()
|
|
yield
|
|
await Tortoise.close_connections()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title=settings.APP_TITLE,
|
|
description=settings.APP_DESCRIPTION,
|
|
version=settings.VERSION,
|
|
openapi_url="/openapi.json",
|
|
middleware=make_middlewares(),
|
|
lifespan=lifespan,
|
|
redirect_slashes=False, # 禁用尾部斜杠重定向
|
|
)
|
|
# 注册静态文件目录
|
|
# app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|
register_exceptions(app)
|
|
register_routers(app, prefix="/api")
|
|
return app
|
|
|
|
|
|
app = create_app()
|