Merge branch 'we-code' into develop
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-bootstrap</artifactId>
|
||||
|
||||
<version>2.3.0</version>
|
||||
|
||||
<properties>
|
||||
|
||||
43
fizz-bootstrap/src/main/java/we/MyApiConfig.java
Normal file
43
fizz-bootstrap/src/main/java/we/MyApiConfig.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package we;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import we.config.ManualApiConfig;
|
||||
import we.plugin.PluginConfig;
|
||||
import we.plugin.auth.ApiConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定义 MyApiConfig 继承 ManualApiConfig, 并注解为 Configuration,
|
||||
* 然后实现 setApiConfigs 方法,在方法中添加路由配置
|
||||
*/
|
||||
@Configuration
|
||||
public class MyApiConfig extends ManualApiConfig {
|
||||
|
||||
@Override
|
||||
public List<ApiConfig> setApiConfigs() {
|
||||
|
||||
List<ApiConfig> apiConfigs = new ArrayList<>();
|
||||
|
||||
ApiConfig ac = new ApiConfig(); // 一个路由配置
|
||||
ac.id = 1000; // 路由 id,建议从 1000 开始
|
||||
ac.service = "xservice"; // 前端服务名
|
||||
ac.path = "/ypath"; // 前端路径
|
||||
ac.type = ApiConfig.Type.REVERSE_PROXY; // 路由类型,此处为反向代理
|
||||
ac.httpHostPorts = Collections.singletonList("http://127.0.0.1:9094"); // 被代理接口的地址
|
||||
// ac.httpHostPorts = Collections.singletonList("https://self-signed.badssl.com");
|
||||
ac.backendPath = "/@ypath"; // 被代理接口的路径
|
||||
// ac.backendPath = "/";
|
||||
ac.pluginConfigs = new ArrayList<>();
|
||||
PluginConfig pc = new PluginConfig();
|
||||
pc.plugin = "myPlugin"; // 应用 id 为 myPlugin 的插件
|
||||
ac.pluginConfigs.add(pc);
|
||||
|
||||
apiConfigs.add(ac);
|
||||
|
||||
log.info("set api configs end");
|
||||
return apiConfigs; // 返回路由配置
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.0</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.0</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.0</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
21
fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java
Normal file
21
fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package we.plugin.myplugin;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
import we.plugin.FizzPluginFilter;
|
||||
import we.plugin.FizzPluginFilterChain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component(MyPlugin.MY_PLUGIN) // 必须,且为插件 id
|
||||
public class MyPlugin implements FizzPluginFilter {
|
||||
|
||||
public static final String MY_PLUGIN = "myPlugin"; // 插件 id
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, Map<String, Object> config) {
|
||||
System.err.println("this is my plugin"); // 本插件只输出这个
|
||||
return FizzPluginFilterChain.next(exchange); // 执行后续逻辑
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.0</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
Reference in New Issue
Block a user