fix(web): override redoc endpoint with pinned JS v3.0.0-rc.0

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 <noreply@anthropic.com>
This commit is contained in:
GitHub
2026-06-12 17:05:25 +08:00
co-authored by Claude
parent 9848d754a8
commit 79c81cc3b6
+13 -1
View File
@@ -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