news-classifier/crawler-module/start_web.py

41 lines
984 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
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"
)