-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_server.py
More file actions
51 lines (43 loc) · 1.25 KB
/
start_server.py
File metadata and controls
51 lines (43 loc) · 1.25 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
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
忆路智规后端服务器启动脚本
"""
import os
import sys
import uvicorn
from pathlib import Path
# 添加backend目录到Python路径
backend_dir = Path(__file__).parent / "backend"
sys.path.insert(0, str(backend_dir))
# 导入迁移脚本
from backend.migrate_db import migrate_database
def main():
"""启动服务器"""
print("🚀 启动忆路智规后端服务器...")
# 先运行数据库迁移
try:
migrate_database()
except Exception as e:
print(f"❌ 数据库迁移失败: {e}")
print("⚠️ 尝试继续启动服务器...")
print("📍 API文档地址: http://localhost:8000/docs")
print("📍 ReDoc文档地址: http://localhost:8000/redoc")
print("📍 健康检查: http://localhost:8000/health")
print("-" * 50)
try:
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level="info",
app_dir=str(backend_dir)
)
except KeyboardInterrupt:
print("\n🛑 服务器已停止")
except Exception as e:
print(f"❌ 服务器启动失败: {e}")
sys.exit(1)
if __name__ == "__main__":
main()