Skip to content

Commit 16cd692

Browse files
author
jiangwh
committed
add gateway config
1 parent af4a976 commit 16cd692

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

springcloud/springcloudgateway.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 定义路由
2+
3+
增加Normal路由信息
4+
5+
```bash
6+
curl -X POST -H "Content-Type: application/json" -d '{"id":"sina","predicates":[{"args":{"_genkey_2":"/sina/**"},"name":"Path"}],"filters":[],"uri":"https://www.sina.com","order":"2"}' 127.0.0.1:8080/actuator/gateway/routes/sina
7+
```
8+
9+
定义查询路由信息
10+
11+
```bash
12+
curl -X POST -H "Content-Type: application/json" -d '{"id":"sina","predicates":[{"args":{"param":"s","regexp":"1"},"name":"Query"}],"filters":[],"uri":"https://www.baidu.com","order":"1"}' 127.0.0.1:8080/actuator/gateway/routes/sina
13+
```
14+
15+
16+
17+
增加fallback路由
18+
19+
```bash
20+
curl -X POST -H "Content-Type: application/json" -d '{"id":"sina","predicates":[{"args":{"_genkey_2":"/sina/**"},"name":"Path"}],"filters":[{"args":{"name":"fallbackcmd","fallbackUri" :"forward:/hystrixfallback"},"name":"Hystrix"}],"uri":"https://www.sccina.com","order":"2"}' 127.0.0.1:8080/actuator/gateway/routes/sina -vvv
21+
```
22+
23+
增加域名 路径匹配
24+
25+
```bash
26+
curl -X POST -H "Content-Type: application/json" -d '{"id":"sina","predicates":[{"args":{"_genkey_2":"/baidu/**"},"name":"Path"},{"args":{"_genkey_3":"www.baidu.com"},"name":"Host"}],"filters":[],"uri":"https://www.baidu.com","order":"1"}' 127.0.0.1:8080/actuator/gateway/routes/sina
27+
```
28+
29+
路径重写
30+
31+
```bash
32+
curl -X POST -H "Content-Type: application/json" -d '{"id":"sina","predicates":[{"args":{"_genkey_2":"/baidu/**"},"name":"Path"}],"filters":[{"name":"RewritePath","args":{"regexp":"/baidu","replacement":"/"}}],"uri":"https://www.baidu.com","order":"1"}' 127.0.0.1:8080/actuator/gateway/routes/sina
33+
```
34+
35+
36+
37+
## 如何确定filter或者predicate的参数
38+
39+
```java
40+
//HystrixGatewayFilterFactory
41+
//转为map
42+
public static class Config {
43+
private String name;
44+
private Setter setter;
45+
private URI fallbackUri;
46+
}
47+
48+
//QueryRoutePredicateFactory
49+
public static class Config {
50+
@NotEmpty
51+
private String param;
52+
private String regexp;
53+
}
54+
```
55+

0 commit comments

Comments
 (0)