Gateway高级配置
jeecg 路由加载支持三种模式: database数据库
,yml本地配置
、 nacos配置
,其中nacos和数据库方式支持动态刷新路由!默认用的是database数据库
模式。
路由加载模式说明
配置模式 | 配置加载方式 |
---|---|
database | 走系统的路由管理DB |
yml | 本地配置文件 application.yml |
nacos | 走nacos的 jeecg-gateway-router.json |
以下介绍三种模式的配置方式
切换路由需修改nacos中的 jeecg-gateway-dev.yml
中路由配置如下图
模式一: 数据库配置方式
修改 jeecg-gateway-dev.yml
中的 jeecg.route.config.data-type=database
再通过系统管理下的路由配置菜单进行路由维护,路由配置表为sys_gateway_route
这样gateway 路由加载就从数据库中读取。
界面可视化配置参考如下
模式二:本地yml配置方式
修改 jeecg-gateway-dev.yml
中的 jeecg.route.config.data-type=yml,并在里面添加如下路由配置
spring:
cloud:
gateway:
routes:
- id: jeecg-demo
uri: lb://jeecg-demo
predicates:
- Path=/mock/**,/test/**,/bigscreen/template1/**,/bigscreen/template2/**
- id: jeecg-system
uri: lb://jeecg-system
predicates:
- Path=/sys/**,/eoa/plan/**,/email/**,/oa/im/**,/metting/**,/filemanage/**,/officialdoc/**,/sign/**,/oa/im/**,/cms/**,/chat/eoaCmsMenu/**,/filedisk/**,/im/**,/joa/**,/online/**,/bigscreen/**,/jmreport/**,/design/report/**,/desform/**,/process/**,/act/**,/plug-in/**
- id: jeecg-system-websocket
uri: lb:ws://jeecg-system
predicates:
- Path=/websocket/**,/eoaSocket/**
- id: jeecg-demo-websocket
uri: lb:ws://jeecg-demo
predicates:
- Path=/vxeSocket/**
模式三: nacos配置方式
修改 jeecg-gateway-dev.yml
中的 jeecg.route.config.data-type=nacos
再在nacos中新建路由配置文件 jeecg-gateway-router.json
GateWay路由条件配置
1、时间点后匹配
yml方式配置
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2022-02-20T17:42:47.789-07:00[America/Denver]
2、时间点前匹配
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://example.org
predicates:
- Before=2022-02-20T17:42:47.789-07:00[America/Denver]
3、时间区间匹配
spring:
cloud:
gateway:
routes:
- id: between_route
uri: https://example.org
predicates:
- Between=2022-01-20T17:42:47.789-07:00[America/Denver],
2022-01-21T17:42:47.789-07:00[America/Denver]
4、指定Cookie正则匹配指定值
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=cookie,china
5、指定Header正则匹配指定值
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id
6、请求Host匹配指定值
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.somehost.org,**.anotherhost.org
7、请求Method匹配指定请求方式
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
8、请求路径正则匹配
spring:
cloud:
gateway:
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
9、请求包含某参数
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
10、请求包含某参数并且参数值匹配正则表达式
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=red, gree.
11、远程地址匹配
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24