| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/usr/bin/env python3
- """
- 测试服务器 - 使用8001端口
- """
- import sys
- import os
- # 添加src目录到Python路径
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
- # 加载环境变量
- from dotenv import load_dotenv
- load_dotenv()
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- # 创建FastAPI应用
- app = FastAPI(
- title="SSO认证中心",
- version="1.0.0",
- description="OAuth2单点登录认证中心",
- docs_url="/docs",
- redoc_url="/redoc"
- )
- # 配置CORS
- app.add_middleware(
- CORSMiddleware,
- allow_origins=["*"],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- @app.get("/")
- async def root():
- """根路径"""
- return {
- "message": "SSO认证中心测试服务器",
- "version": "1.0.0",
- "status": "running",
- "port": 8001,
- "docs": "/docs"
- }
- @app.get("/health")
- async def health_check():
- """健康检查"""
- return {
- "status": "healthy",
- "message": "服务正常运行",
- "port": 8001
- }
- @app.get("/test")
- async def test_endpoint():
- """测试端点"""
- return {
- "message": "测试成功",
- "port": 8001,
- "data": {
- "server": "FastAPI",
- "python_version": sys.version,
- "working_directory": os.getcwd()
- }
- }
- if __name__ == "__main__":
- import uvicorn
- print("启动测试服务器...")
- print("访问地址: http://localhost:8001")
- print("API文档: http://localhost:8001/docs")
- print("按 Ctrl+C 停止服务器")
-
- uvicorn.run(
- app,
- host="0.0.0.0",
- port=8001,
- log_level="info"
- )
|