313 lines
7.8 KiB
Markdown
313 lines
7.8 KiB
Markdown
|
|
# 项目路由分析报告
|
|||
|
|
|
|||
|
|
## 统一前缀路由
|
|||
|
|
|
|||
|
|
### API 路由前缀
|
|||
|
|
**主要前缀:`/api/`**
|
|||
|
|
|
|||
|
|
所有后端 REST API 接口统一使用 `/api/` 作为前缀。
|
|||
|
|
|
|||
|
|
## 详细路由分类
|
|||
|
|
|
|||
|
|
### 1. REST API 路由(`/api/`)
|
|||
|
|
|
|||
|
|
#### 认证授权模块
|
|||
|
|
- `/api/auth/**` - 用户认证(登录、注册)
|
|||
|
|
- `/api/verification/**` - 验证码服务
|
|||
|
|
- `/api/email/**` - 邮件服务
|
|||
|
|
- `/api/tencent/**` - 腾讯云服务集成
|
|||
|
|
|
|||
|
|
#### 视频生成模块
|
|||
|
|
- `/api/text-to-video/**` - 文生视频
|
|||
|
|
- `/api/image-to-video/**` - 图生视频
|
|||
|
|
- `/api/storyboard-video/**` - 分镜视频
|
|||
|
|
|
|||
|
|
#### 用户作品模块
|
|||
|
|
- `/api/works/**` - 用户作品管理
|
|||
|
|
|
|||
|
|
#### 支付订单模块
|
|||
|
|
- `/api/payments/**` - 支付相关
|
|||
|
|
- `/api/payments/alipay/**` - 支付宝支付
|
|||
|
|
- `/api/orders/**` - 订单管理
|
|||
|
|
|
|||
|
|
#### 会员积分模块
|
|||
|
|
- `/api/members/**` - 会员管理
|
|||
|
|
- `/api/points/**` - 积分系统
|
|||
|
|
|
|||
|
|
#### 任务管理模块
|
|||
|
|
- `/api/task-queue/**` - 任务队列
|
|||
|
|
- `/api/task-status/**` - 任务状态
|
|||
|
|
- `/api/cleanup/**` - 任务清理
|
|||
|
|
|
|||
|
|
#### 管理后台模块
|
|||
|
|
- `/api/admin/**` - 管理员接口
|
|||
|
|
- `/api/dashboard/**` - 数据仪表盘
|
|||
|
|
- `/api/analytics/**` - 数据分析
|
|||
|
|
|
|||
|
|
#### 系统设置模块
|
|||
|
|
- `/api/api-key/**` - API 密钥管理
|
|||
|
|
- `/api/prompt/**` - 提示词优化
|
|||
|
|
|
|||
|
|
#### 测试诊断模块
|
|||
|
|
- `/api/test/**` - 测试接口
|
|||
|
|
- `/api/diagnostic/**` - 诊断接口
|
|||
|
|
- `/api/polling/**` - 轮询测试
|
|||
|
|
- `/api/polling-diagnostic/**` - 轮询诊断
|
|||
|
|
- `/api/monitor/**` - 监控接口
|
|||
|
|
|
|||
|
|
#### 公共接口
|
|||
|
|
- `/api/public/**` - 公共API(无需认证)
|
|||
|
|
- `/api/health/**` - 健康检查接口
|
|||
|
|
|
|||
|
|
### 2. 页面路由(非 API)
|
|||
|
|
|
|||
|
|
#### 用户页面
|
|||
|
|
- `/login` - 登录页面
|
|||
|
|
- `/register` - 注册页面
|
|||
|
|
- `/payment/**` - 支付页面
|
|||
|
|
- `/orders/**` - 订单页面
|
|||
|
|
|
|||
|
|
#### 管理员页面
|
|||
|
|
- `/settings/**` - 系统设置页面(管理员)
|
|||
|
|
- `/users/**` - 用户管理页面(管理员)
|
|||
|
|
|
|||
|
|
#### 开发工具
|
|||
|
|
- `/h2-console/**` - H2 数据库控制台(开发环境)
|
|||
|
|
|
|||
|
|
### 3. API 文档路由
|
|||
|
|
|
|||
|
|
- `/swagger-ui.html` - Swagger UI 主页
|
|||
|
|
- `/swagger-ui/**` - Swagger UI 资源
|
|||
|
|
- `/v3/api-docs/**` - OpenAPI 文档 JSON
|
|||
|
|
- `/swagger-resources/**` - Swagger 资源
|
|||
|
|
- `/webjars/**` - Web 资源库
|
|||
|
|
|
|||
|
|
### 4. 静态资源路由
|
|||
|
|
|
|||
|
|
- `/css/**` - CSS 样式文件
|
|||
|
|
- `/js/**` - JavaScript 文件
|
|||
|
|
- `/uploads/**` - 上传文件
|
|||
|
|
|
|||
|
|
## 路由代理配置
|
|||
|
|
|
|||
|
|
### Nginx 代理配置
|
|||
|
|
|
|||
|
|
#### 1. API 代理(推荐配置)
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# API 代理到后端
|
|||
|
|
location /api/ {
|
|||
|
|
proxy_pass http://172.22.0.1:8080/;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
|
|||
|
|
# 超时设置(视频生成可能需要较长时间)
|
|||
|
|
proxy_connect_timeout 30s;
|
|||
|
|
proxy_send_timeout 900s;
|
|||
|
|
proxy_read_timeout 900s;
|
|||
|
|
|
|||
|
|
# 支持大文件上传
|
|||
|
|
client_max_body_size 600M;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 2. Swagger UI 代理(可选,用于生产环境)
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# API 文档代理
|
|||
|
|
location ~ ^/(swagger-ui|v3/api-docs|swagger-resources|webjars) {
|
|||
|
|
proxy_pass http://172.22.0.1:8080;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3. 上传文件代理
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# 上传文件代理
|
|||
|
|
location /uploads/ {
|
|||
|
|
proxy_pass http://172.22.0.1:8080;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
|
|||
|
|
# 缓存设置
|
|||
|
|
expires 7d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 4. WebSocket 支持(如果需要)
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
location /ws/ {
|
|||
|
|
proxy_pass http://172.22.0.1:8080;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection "upgrade";
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Apache 代理配置(如果使用 Apache)
|
|||
|
|
|
|||
|
|
```apache
|
|||
|
|
# 启用代理模块
|
|||
|
|
LoadModule proxy_module modules/mod_proxy.so
|
|||
|
|
LoadModule proxy_http_module modules/mod_proxy_http.so
|
|||
|
|
|
|||
|
|
# API 代理
|
|||
|
|
ProxyPass /api/ http://172.22.0.1:8080/
|
|||
|
|
ProxyPassReverse /api/ http://172.22.0.1:8080/
|
|||
|
|
|
|||
|
|
# Swagger UI 代理
|
|||
|
|
ProxyPass /swagger-ui/ http://172.22.0.1:8080/swagger-ui/
|
|||
|
|
ProxyPassReverse /swagger-ui/ http://172.22.0.1:8080/swagger-ui/
|
|||
|
|
|
|||
|
|
ProxyPass /v3/api-docs/ http://172.22.0.1:8080/v3/api-docs/
|
|||
|
|
ProxyPassReverse /v3/api-docs/ http://172.22.0.1:8080/v3/api-docs/
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 权限配置
|
|||
|
|
|
|||
|
|
### 无需认证(公开访问)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
/login
|
|||
|
|
/register
|
|||
|
|
/api/public/**
|
|||
|
|
/api/auth/**
|
|||
|
|
/api/verification/**
|
|||
|
|
/api/email/**
|
|||
|
|
/api/tencent/**
|
|||
|
|
/api/test/**
|
|||
|
|
/api/orders/stats
|
|||
|
|
/api/payments/alipay/notify
|
|||
|
|
/api/payments/alipay/return
|
|||
|
|
/swagger-ui/**
|
|||
|
|
/v3/api-docs/**
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 需要认证
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
/api/orders/**(除 /api/orders/stats)
|
|||
|
|
/api/payments/**(除支付宝回调)
|
|||
|
|
/api/image-to-video/**
|
|||
|
|
/api/text-to-video/**
|
|||
|
|
/api/works/**
|
|||
|
|
/api/points/**
|
|||
|
|
/api/members/**
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 需要管理员权限
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
/api/dashboard/**
|
|||
|
|
/api/admin/**
|
|||
|
|
/settings/**
|
|||
|
|
/users/**
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 完整 Nginx 配置示例
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
server {
|
|||
|
|
listen 80;
|
|||
|
|
server_name localhost;
|
|||
|
|
root /www/wwwroot/your-domain.com;
|
|||
|
|
index index.html index.htm;
|
|||
|
|
|
|||
|
|
# 开启gzip压缩
|
|||
|
|
gzip on;
|
|||
|
|
gzip_vary on;
|
|||
|
|
gzip_min_length 1024;
|
|||
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
|
|||
|
|
|
|||
|
|
# 前端路由支持(History模式)
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ /index.html;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# API 代理到后端(主要路由)
|
|||
|
|
location /api/ {
|
|||
|
|
proxy_pass http://172.22.0.1:8080/;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
|
|||
|
|
# 超时设置
|
|||
|
|
proxy_connect_timeout 30s;
|
|||
|
|
proxy_send_timeout 900s;
|
|||
|
|
proxy_read_timeout 900s;
|
|||
|
|
|
|||
|
|
# 支持大文件上传
|
|||
|
|
client_max_body_size 600M;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Swagger UI 代理
|
|||
|
|
location ~ ^/(swagger-ui|v3/api-docs|swagger-resources|webjars) {
|
|||
|
|
proxy_pass http://172.22.0.1:8080;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 上传文件代理
|
|||
|
|
location /uploads/ {
|
|||
|
|
proxy_pass http://172.22.0.1:8080;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
expires 7d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 静态资源缓存
|
|||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|||
|
|
expires 1y;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 禁止访问隐藏文件
|
|||
|
|
location ~ /\. {
|
|||
|
|
deny all;
|
|||
|
|
access_log off;
|
|||
|
|
log_not_found off;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 宝塔面板配置
|
|||
|
|
|
|||
|
|
在宝塔面板中配置反向代理:
|
|||
|
|
|
|||
|
|
1. 进入网站设置 → 反向代理
|
|||
|
|
2. 添加反向代理规则:
|
|||
|
|
- **代理名称**: API代理
|
|||
|
|
- **目标URL**: http://172.22.0.1:8080
|
|||
|
|
- **发送域名**: $host
|
|||
|
|
- **代理路径**: /api/
|
|||
|
|
- **缓存**: 关闭
|
|||
|
|
|
|||
|
|
## 总结
|
|||
|
|
|
|||
|
|
- **统一API前缀**: `/api/`
|
|||
|
|
- **后端服务地址**: `http://172.22.0.1:8080`
|
|||
|
|
- **主要代理路径**: `/api/` → `http://172.22.0.1:8080/`
|
|||
|
|
- **文档访问**: `/swagger-ui.html`
|
|||
|
|
- **特殊配置**: 需要支持大文件上传(600M)和长时间请求(15分钟)
|
|||
|
|
|