diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 0cb813a..a9e6cd1 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -12,6 +12,7 @@ com.fizzgate fizz-bootstrap + 2.3.0 diff --git a/fizz-bootstrap/src/main/java/we/MyApiConfig.java b/fizz-bootstrap/src/main/java/we/MyApiConfig.java new file mode 100644 index 0000000..8099b54 --- /dev/null +++ b/fizz-bootstrap/src/main/java/we/MyApiConfig.java @@ -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 setApiConfigs() { + + List 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; // 返回路由配置 + } +} diff --git a/fizz-common/pom.xml b/fizz-common/pom.xml index 6d32363..f47b0c7 100644 --- a/fizz-common/pom.xml +++ b/fizz-common/pom.xml @@ -5,7 +5,9 @@ fizz-gateway-community com.fizzgate + 2.3.0 + ../pom.xml 4.0.0 diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml index f766b75..517d6c6 100644 --- a/fizz-core/pom.xml +++ b/fizz-core/pom.xml @@ -5,7 +5,9 @@ fizz-gateway-community com.fizzgate + 2.3.0 + ../pom.xml 4.0.0 diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml index 99e20d1..f43a51c 100644 --- a/fizz-plugin/pom.xml +++ b/fizz-plugin/pom.xml @@ -5,7 +5,9 @@ fizz-gateway-community com.fizzgate + 2.3.0 + ../pom.xml 4.0.0 diff --git a/fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java b/fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java new file mode 100644 index 0000000..753d65c --- /dev/null +++ b/fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java @@ -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 filter(ServerWebExchange exchange, Map config) { + System.err.println("this is my plugin"); // 本插件只输出这个 + return FizzPluginFilterChain.next(exchange); // 执行后续逻辑 + } +} diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml index 6cf2fad..585c7db 100644 --- a/fizz-spring-boot-starter/pom.xml +++ b/fizz-spring-boot-starter/pom.xml @@ -5,7 +5,9 @@ fizz-gateway-community com.fizzgate + 2.3.0 + ../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 609b11b..83112eb 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,9 @@ fizz-gateway-community ${project.artifactId} fizz gateway community + 2.3.0 + pom fizz-common