This commit is contained in:
2025-03-31 20:54:25 +08:00
parent 46f63d22da
commit 52969426a2
11 changed files with 91 additions and 79 deletions

View File

@@ -1,8 +1,20 @@
"use client";
import { useEffect } from 'react';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
// 动态导入,避免生产环境问题
let SwaggerUI = () => <div>Swagger UI is not available in production</div>;
let swaggerCss = null;
// 只在开发环境中导入 Swagger UI
if (process.env.NODE_ENV === 'development') {
try {
SwaggerUI = require('swagger-ui-react').default;
require('swagger-ui-react/swagger-ui.css');
} catch (e) {
console.error('Failed to load Swagger UI:', e);
}
}
export default function SwaggerPage() {
useEffect(() => {
@@ -10,6 +22,21 @@ export default function SwaggerPage() {
document.title = 'API Documentation - ShortURL Analytics';
}, []);
// 生产环境显示替代内容
if (process.env.NODE_ENV !== 'development') {
return (
<div className="p-8 max-w-4xl mx-auto">
<h1 className="text-2xl font-bold mb-4">API Documentation</h1>
<p className="mb-4">
Swagger UI is only available in development environment.
</p>
<p>
Please run the application in development mode to access the full API documentation.
</p>
</div>
);
}
// Swagger配置
const swaggerConfig = {
openapi: '3.0.0',