aidmt-ms/docs/gateway-routes-config.md

96 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 网关路由配置说明
## 问题分析
用户管理和部门管理的 Swagger 接口不显示,可能是因为网关路由配置缺失。
## 网关路由配置位置
网关路由配置在 **Nacos 配置中心**,配置文件名:`application-dev.yml`(根据环境可能是 `application-prod.yml` 等)
## 需要检查的配置
### 1. 登录 Nacos 控制台
- 地址:`http://127.0.0.1:8848/nacos`
- 用户名/密码:`nacos/nacos`(默认)
### 2. 查找配置文件
- **Data ID**: `application-dev.yml`
- **Group**: `DEFAULT_GROUP`
- **命名空间**: 根据实际情况选择
### 3. 检查路由配置
网关路由配置应该包含以下内容:
```yaml
spring:
cloud:
gateway:
discovery:
locator:
enabled: true # 启用服务发现自动路由
lower-case-service-id: true # 服务ID转小写
routes:
# ruoyi-system 路由配置
- id: ruoyi-system
uri: lb://ruoyi-system
predicates:
- Path=/system/**
filters:
- StripPrefix=1
# ruoyi-manage 路由配置
- id: ruoyi-manage
uri: lb://ruoyi-manage
predicates:
- Path=/manage/**
filters:
- StripPrefix=1
# Swagger 路由配置
- id: ruoyi-system-swagger
uri: lb://ruoyi-system
predicates:
- Path=/ruoyi-system/v3/api-docs/**
filters:
- StripPrefix=1
- id: ruoyi-manage-swagger
uri: lb://ruoyi-manage
predicates:
- Path=/ruoyi-manage/v3/api-docs/**
filters:
- StripPrefix=1
```
## 如果配置不存在
如果 Nacos 中没有上述路由配置,需要添加:
1. 登录 Nacos 控制台
2. 进入"配置管理" -> "配置列表"
3. 找到或创建 `application-dev.yml`
4. 添加上述路由配置
5. 发布配置
6. 重启网关服务
## 验证步骤
1. **检查服务注册**:在 Nacos 控制台的"服务管理" -> "服务列表"中,确认以下服务已注册:
- `ruoyi-system`
- `ruoyi-manage`
2. **检查路由**:访问以下 URL 验证路由是否正常:
- `http://localhost:8080/system/user/list` - 系统模块用户列表
- `http://localhost:8080/manage/unit/archive/list` - 管理模块单位建档列表
- `http://localhost:8080/ruoyi-system/v3/api-docs` - 系统模块 Swagger 文档
- `http://localhost:8080/ruoyi-manage/v3/api-docs` - 管理模块 Swagger 文档
3. **检查 Swagger UI**
- 访问:`http://localhost:8080/swagger-ui.html` 或 `http://localhost:8080/doc.html`
- 在服务下拉列表中应该能看到 `ruoyi-system``ruoyi-manage`
## 注意事项
- 如果启用了 `discovery.locator.enabled: true`,网关会自动为所有注册的服务创建路由,路径格式为:`/服务名/**`
- 但为了更好的控制和明确的路由规则,建议显式配置路由
- 路由配置修改后需要重启网关服务才能生效