001spring-cloud-gateway
一、spring-cloud-starter-gateway
spring: # Spring Boot配置文件的根节点
application: # 应用程序配置
name: fp-sass-gateway # 应用程序名称
cloud: # Spring Cloud配置
gateway: # 网关配置
enabled: true # 启用Spring Cloud Gateway
routes: # 配置路由列表
- id: path_route # 路由的唯一标识符
predicates: # 匹配请求的条件
- Path=/baidu # 匹配路径为/baidu的请求
filters: # 对请求进行过滤和修改
- StripPrefix=1 # 去除一级路径前缀
uri: https://www.baidu.com # 目标服务的URL
# 请求头匹配
- id: header_route # 路由的唯一标识符
predicates: # 匹配请求的条件
- Header=user,long # 匹配请求头中包含user和long字段的请求
uri: https://www.baidu.com # 目标服务的URL
# 组合匹配
- id: compose # 路由的唯一标识符
predicates: # 匹配请求的条件
- Path=/abc # 匹配路径为/abc的请求
- Header=user,test # 匹配请求头中包含user和test字段的请求
filters: # 对请求进行过滤和修改
- StripPrefix=1 # 去除一级路径前缀
uri: https://www.bilibili.com # 目标服务的URL
效果:

二、实现如上功能的对应代码



浙公网安备 33010602011771号