diff --git a/src/easy_tdx/web/app.py b/src/easy_tdx/web/app.py index e047d3e..a5c4803 100644 --- a/src/easy_tdx/web/app.py +++ b/src/easy_tdx/web/app.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from collections.abc import AsyncGenerator from contextlib import asynccontextmanager +from typing import Any from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -102,9 +103,20 @@ def _create_app( description="通达信行情数据 REST + WebSocket API", version="1.0.0", lifespan=lifespan, - redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@3.0.0-rc.0/bundle/redoc.js", + redoc_url=None, # 手动注册 redoc 端点以控制 JS CDN URL ) + # 手动注册 ReDoc 端点,使用固定版本的 JS(默认 redoc@next 已 404) + from fastapi.openapi.docs import get_redoc_html + + @app.get("/redoc", include_in_schema=False) + async def redoc_html() -> Any: + return get_redoc_html( + openapi_url=app.openapi_url or "/openapi.json", + title=app.title + " - ReDoc", + redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@3.0.0-rc.0/bundle/redoc.js", + ) + # Store connection config in app.state for lifespan to use app.state.tdx_host = host app.state.tdx_port = port