From 79c81cc3b6dfdc5bfd969deeee629ac6c1ef7131 Mon Sep 17 00:00:00 2001 From: GitHub Date: Fri, 12 Jun 2026 17:05:25 +0800 Subject: [PATCH] fix(web): override redoc endpoint with pinned JS v3.0.0-rc.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FastAPI does not accept redoc_js_url as a constructor param — the old approach silently ignored it, leaving the default redoc@next CDN URL (which returns 404). Manually register /redoc with get_redoc_html() using the fixed v3.0.0-rc.0 bundle URL. Co-Authored-By: Claude --- src/easy_tdx/web/app.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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