promotion:完成网关的转发

This commit is contained in:
YunaiV 2023-10-22 22:49:40 +08:00
parent 93715790ae
commit 52f014b195
8 changed files with 104 additions and 9 deletions

View File

@ -84,7 +84,7 @@ spring:
- Path=/admin-api/mp/** - Path=/admin-api/mp/**
filters: filters:
- RewritePath=/admin-api/mp/v3/api-docs, /v3/api-docs - RewritePath=/admin-api/mp/v3/api-docs, /v3/api-docs
## member-server 服务 ## product-server 服务
- id: product-admin-api # 路由的编号 - id: product-admin-api # 路由的编号
uri: grayLb://product-server uri: grayLb://product-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组 predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
@ -97,6 +97,19 @@ spring:
- Path=/app-api/product/** - Path=/app-api/product/**
filters: filters:
- RewritePath=/app-api/product/v3/api-docs, /v3/api-docs - RewritePath=/app-api/product/v3/api-docs, /v3/api-docs
## promotion-server 服务
- id: promotion-admin-api # 路由的编号
uri: grayLb://promotion-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/promotion/**
filters:
- RewritePath=/admin-api/promotion/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: promotion-app-api # 路由的编号
uri: grayLb://promotion-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/promotion/**
filters:
- RewritePath=/app-api/promotion/v3/api-docs, /v3/api-docs
x-forwarded: x-forwarded:
prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀 prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀
@ -123,6 +136,9 @@ knife4j:
- name: mp-server - name: mp-server
service-name: mp-server service-name: mp-server
url: /admin-api/mp/v3/api-docs url: /admin-api/mp/v3/api-docs
- name: member-server - name: product-server
service-name: member-server service-name: product-server
url: /admin-api/member/v3/api-docs url: /admin-api/product/v3/api-docs
- name: promotion-server
service-name: promotion-server
url: /admin-api/promotion/v3/api-docs

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.promotion.enums;
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
/**
* API 相关的枚举
*
* @author 芋道源码
*/
public class ApiConstants {
/**
* 服务名
*
* 注意需要保证和 spring.application.name 保持一致
*/
public static final String NAME = "promotion-server";
public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/promotion";
public static final String VERSION = "1.0.0";
}

View File

@ -61,10 +61,6 @@
<groupId>cn.iocoder.cloud</groupId> <groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId> <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
</dependency>
<!-- Web 相关 --> <!-- Web 相关 -->
<dependency> <dependency>

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.promotion.framework.rpc.config;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {ProductSkuApi.class, ProductSpuApi.class, ProductCategoryApi.class,
MemberUserApi.class, TradeOrderApi.class})
public class RpcConfiguration {
}

View File

@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.promotion.framework.rpc;

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.promotion.framework.security.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import cn.iocoder.yudao.module.promotion.enums.ApiConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
/**
* Member 模块的 Security 配置
*/
@Configuration("memberSecurityConfiguration")
public class SecurityConfiguration {
@Bean("memberAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {
@Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
// Swagger 接口文档
registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据
.antMatchers("/swagger-ui.html").permitAll(); // Swagger UI
// Spring Boot Actuator 的安全配置
registry.antMatchers("/actuator").anonymous()
.antMatchers("/actuator/**").anonymous();
// Druid 监控
registry.antMatchers("/druid/**").anonymous();
// RPC 服务的安全配置
registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
}
};
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.promotion.framework.security.core;

View File

@ -1,6 +1,6 @@
spring: spring:
application: application:
name: promtoion-server name: promotion-server
profiles: profiles:
active: local active: local