一、 StripPrefix Filter
StripPrefix Filter 是一个请求路径截取的功能。
server:
port: 80js80
spring:
application:
name: user
android cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: user
uri: lb://user
#uri:javascript http://localhost:8080
predicates:
- Path=/zuul/jsapi/user/**
filters:
- StripPrefix=3
主要看这里
- Path=/zuul/api/user/** filters: - StripPrefix=3
当请求路径匹配到/zuul/api/user/**会将包含zuul和后边的字符串接去掉转发,StripPrefix=3就代表截取路径的个数,
这样配置后当请求/zuul/api/user/aaa后端匹配到的请求路径,就会变成http://localhost:8080/aaa
二、PrefixPath Filter
PrefixPath Filter 的作用和 StripPrefix 正相反,是在 URL 路径前面添加一部分的前缀。
server:
port: 8080
spring:
application:
name: user
cloud:
gateway:js
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: user
uri: lb://user
predicates:
- Path=/**
filters:
- PrefixPath=/hi
主要看这里
predicates:
- Path=/**
filters:
# 当访问 http://localhost:8080/aaa,加上前缀就变成 http://localhost:8080/hi/aaa
- PrefixPath=/hi
当访问 http://localhost:8080/aaa,加上前缀就变成 http://localhost:8080/hi/aaa
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
加载中,请稍侯......
精彩评论