From 0a7d6c16c99f9993bb5f1bb0bfaa2a45ab170983 Mon Sep 17 00:00:00 2001 From: golc <2483469113@qq.com> Date: Wed, 4 Mar 2026 11:41:01 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=20Swagger=20UI=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20CDN=20=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决 Vercel serverless 环境中 SwaggerUIBundle 未定义的问题, 使用 jsDelivr CDN 加载 Swagger UI 静态资源。 Co-Authored-By: Claude Sonnet 4.6 --- api/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/index.ts b/api/index.ts index 7589c34..d6440bd 100644 --- a/api/index.ts +++ b/api/index.ts @@ -92,7 +92,17 @@ async function bootstrap() { .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, config); - SwaggerModule.setup('docs', app, document); + + // 配置 Swagger UI 使用 CDN 资源(解决 serverless 环境静态资源问题) + SwaggerModule.setup('docs', app, document, { + customCssUrl: [ + 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.11.0/swagger-ui.css', + ], + customJs: [ + 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.11.0/swagger-ui-bundle.js', + 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.11.0/swagger-ui-standalone-preset.js', + ], + }); await app.init(); cachedApp = expressApp;