from fastapi import FastAPI from fastapi.middleware.gzip import GZipMiddleware from handler.exception import install as exception_install from lifespan import lifespan from plugin import CORSMiddleware, Monitor, PluginManager, Profiler from utils.start import start app: FastAPI = start(lambda: FastAPI(lifespan=lifespan)) # 添加 GZip 中间件 app.add_middleware( GZipMiddleware, minimum_size=1000, # 仅压缩大于 1000 字节的响应 compresslevel=5, # 压缩级别,范围为 1-9,默认值为 9 ) # 安装异常处理中间件 exception_install(app) # 安装需要启动后才能安装插件 plugin_manager = PluginManager(app) plugin_manager.register_plugin(CORSMiddleware(app)) plugin_manager.register_plugin(Monitor(app)) plugin_manager.register_plugin(Profiler(app))