-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_api.py
More file actions
42 lines (33 loc) · 1 KB
/
Copy pathrun_api.py
File metadata and controls
42 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""
API 服务器启动脚本
"""
import os
import sys
# Windows UTF-8 编码支持
if sys.platform == "win32":
os.environ.setdefault("PYTHONIOENCODING", "utf-8")
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
# 添加项目根目录到模块搜索路径
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir)
import uvicorn
from src.api.routes import app
def main():
"""启动 API 服务器"""
host = os.getenv("API_HOST", "0.0.0.0")
port = int(os.getenv("API_PORT", "8000"))
reload = os.getenv("API_RELOAD", "false").lower() == "true"
print(f"启动股票分析 API 服务器: http://{host}:{port}")
print(f"API 文档: http://{host}:{port}/docs")
uvicorn.run(
app,
host=host,
port=port,
reload=reload,
log_level="info"
)
if __name__ == "__main__":
main()