#!/usr/bin/env python3 """ 检查后端服务状态 """ import requests import json def check_backend_status(): """检查后端服务状态""" ports = [8000, 8001, 8002, 8003] for port in ports: try: url = f"http://localhost:{port}" print(f"检查端口 {port}...") response = requests.get(url, timeout=5) if response.status_code == 200: data = response.json() print(f"✅ 端口 {port} 服务正常") print(f" 消息: {data.get('message', 'N/A')}") print(f" 版本: {data.get('version', 'N/A')}") # 检查健康状态 try: health_response = requests.get(f"{url}/health", timeout=5) if health_response.status_code == 200: print(f" 健康检查: ✅ 正常") else: print(f" 健康检查: ❌ 异常 ({health_response.status_code})") except: print(f" 健康检查: ❌ 无响应") # 检查API文档 try: docs_response = requests.get(f"{url}/docs", timeout=5) if docs_response.status_code == 200: print(f" API文档: ✅ 可访问 ({url}/docs)") else: print(f" API文档: ❌ 不可访问") except: print(f" API文档: ❌ 无响应") print(f" 建议前端API地址: {url}") return port except requests.exceptions.ConnectionError: print(f"❌ 端口 {port} 无服务") except requests.exceptions.Timeout: print(f"⏰ 端口 {port} 响应超时") except Exception as e: print(f"❌ 端口 {port} 检查失败: {e}") print("\n❌ 未找到可用的后端服务") print("请先启动后端服务:") print(" python quick_start.py") print(" 或") print(" python test_server.py") return None if __name__ == "__main__": print("=" * 50) print("后端服务状态检查") print("=" * 50) available_port = check_backend_status() if available_port: print(f"\n🎉 找到可用服务: http://localhost:{available_port}") print(f"📚 API文档地址: http://localhost:{available_port}/docs") print(f"\n📝 前端配置建议:") print(f" VITE_API_BASE_URL=http://localhost:{available_port}") else: print(f"\n🚀 启动后端服务:") print(f" cd sso-backend") print(f" python quick_start.py")