41 lines
984 B
Python
41 lines
984 B
Python
"""
|
||
FastAPI服务器启动脚本
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
|
||
# 添加项目根目录到Python路径
|
||
project_root = os.path.dirname(os.path.abspath(__file__))
|
||
sys.path.insert(0, project_root)
|
||
|
||
if __name__ == "__main__":
|
||
import uvicorn
|
||
|
||
# 直接导入app
|
||
from src.api.main import app
|
||
|
||
# 从配置读取
|
||
try:
|
||
from config.settings import config
|
||
web_config = config.get('web', {})
|
||
host = web_config.get('host', '0.0.0.0')
|
||
port = web_config.get('port', 8000)
|
||
except:
|
||
host = '0.0.0.0'
|
||
port = 8000
|
||
|
||
print(f"正在启动FastAPI服务器...")
|
||
print(f"地址: http://{host}:{port}")
|
||
print(f"API文档: http://localhost:{port}/docs")
|
||
print(f"按 CTRL+C 停止服务器\n")
|
||
|
||
# 直接运行app对象,禁用reload(因为reload模式需要import string)
|
||
uvicorn.run(
|
||
app,
|
||
host=host,
|
||
port=port,
|
||
reload=False, # 禁用reload避免警告
|
||
log_level="info"
|
||
)
|