版本跟新
parent
1cb131a491
commit
b4644366e0
|
@ -1,6 +1,6 @@
|
|||
## AdoptOpenJDK 停止发布 OpenJDK 二进制,而 Eclipse Temurin 是它的延伸,提供更好的稳定性
|
||||
## 感谢复旦核博士的建议!灰子哥,牛皮!
|
||||
FROM eclipse-temurin:8-jre
|
||||
FROM eclipse-temurin:21-jre
|
||||
|
||||
## 创建目录,并使用它作为工作目录
|
||||
RUN mkdir -p /yudao-gateway
|
||||
|
|
|
@ -35,11 +35,6 @@
|
|||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId> <!-- 接口文档 -->
|
||||
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
||||
|
|
|
@ -9,7 +9,6 @@ import cn.iocoder.yudao.gateway.util.WebFrameworkUtils;
|
|||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
|
||||
|
@ -22,6 +21,7 @@ import org.springframework.core.io.buffer.DataBufferFactory;
|
|||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ReactiveHttpOutputMessage;
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
|
@ -37,7 +37,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
@ -109,7 +109,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
|
|||
AccessLog gatewayLog = new AccessLog();
|
||||
gatewayLog.setRoute(WebFrameworkUtils.getGatewayRoute(exchange));
|
||||
gatewayLog.setSchema(request.getURI().getScheme());
|
||||
gatewayLog.setRequestMethod(request.getMethodValue());
|
||||
gatewayLog.setRequestMethod(request.getMethod().name());
|
||||
gatewayLog.setRequestUrl(request.getURI().getRawPath());
|
||||
gatewayLog.setQueryParams(request.getQueryParams());
|
||||
gatewayLog.setRequestHeaders(request.getHeaders());
|
||||
|
@ -188,7 +188,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
|
|||
gatewayLog.setUserId(SecurityFrameworkUtils.getLoginUserId(exchange));
|
||||
gatewayLog.setUserType(SecurityFrameworkUtils.getLoginUserType(exchange));
|
||||
gatewayLog.setResponseHeaders(response.getHeaders());
|
||||
gatewayLog.setHttpStatus(response.getStatusCode());
|
||||
gatewayLog.setHttpStatus((HttpStatus) response.getStatusCode());
|
||||
|
||||
// 获取响应类型,如果是 json 就打印
|
||||
String originalResponseContentType = exchange.getAttribute(ServerWebExchangeUtils.ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
|
|||
// TODO 芋艿:这里要精细化翻译,默认返回用户是看不懂的
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
log.error("[responseStatusExceptionHandler][uri({}/{}) 发生异常]", request.getURI(), request.getMethod(), ex);
|
||||
return CommonResult.error(ex.getRawStatusCode(), ex.getReason());
|
||||
return CommonResult.error(ex.getStatusCode().value(), ex.getReason());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,8 @@ public class BannerApplicationRunner implements ApplicationRunner {
|
|||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
ThreadUtil.execute(() -> {
|
||||
ThreadUtil.sleep(1, TimeUnit.SECONDS); // 延迟 1 秒,保证输出到结尾
|
||||
//ThreadUtil.sleep(1, TimeUnit.SECONDS); // 延迟 1 秒,保证输出到结尾
|
||||
log.info("Yudao-Gateway 启动成功");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ package cn.iocoder.yudao.gateway.util;
|
|||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import cn.iocoder.yudao.gateway.filter.security.LoginUser;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
@ -106,11 +104,10 @@ public class SecurityFrameworkUtils {
|
|||
* @param builder 请求
|
||||
* @param user 用户
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static void setLoginUserHeader(ServerHttpRequest.Builder builder, LoginUser user) {
|
||||
try {
|
||||
String userStr = JsonUtils.toJsonString(user);
|
||||
userStr = URLEncoder.encode(userStr, StandardCharsets.UTF_8.name()); // 编码,避免中文乱码
|
||||
userStr = URLEncoder.encode(userStr, StandardCharsets.UTF_8); // 编码,避免中文乱码
|
||||
builder.header(LOGIN_USER_HEADER, userStr);
|
||||
} catch (Exception ex) {
|
||||
log.error("[setLoginUserHeader][序列化 user({}) 发生异常]", user, ex);
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
username: # Nacos 账号
|
||||
password: # Nacos 密码
|
||||
server-addr: 192.168.1.128:8848 # Nacos 服务器地址
|
||||
username: nacos # Nacos 账号
|
||||
password: nacos # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
username: # Nacos 账号
|
||||
password: # Nacos 密码
|
||||
server-addr: 192.168.1.128:8848 # Nacos 服务器地址
|
||||
username: nacos # Nacos 账号
|
||||
password: nacos # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
--- #################### 注册中心 + 配置中心相关配置 ####################
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: 192.168.1.128:8848 # Nacos 服务器地址
|
||||
username: nacos # Nacos 账号
|
||||
password: nacos # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
config: # 【注册中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
|
@ -18,6 +18,45 @@ spring:
|
|||
gateway:
|
||||
# 路由配置项,对应 RouteDefinition 数组
|
||||
routes:
|
||||
## hsfx-server 服务
|
||||
- id: hsfx-admin-api # 路由的编号
|
||||
uri: grayLb://hsfx-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/admin-api/hsfx/**
|
||||
filters:
|
||||
- RewritePath=/admin-api/hsfx/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v2/api-docs
|
||||
- id: hsfx-app-api # 路由的编号
|
||||
uri: grayLb://hsfx-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/app-api/hsfx/**
|
||||
filters:
|
||||
- RewritePath=/app-api/hsfx/v3/api-docs, /v3/api-docs
|
||||
## hshy-server 服务
|
||||
- id: hshy-admin-api # 路由的编号
|
||||
uri: grayLb://hshy-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/admin-api/hshy/**
|
||||
filters:
|
||||
- RewritePath=/admin-api/hshy/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v2/api-docs
|
||||
- id: hshy-app-api # 路由的编号
|
||||
uri: grayLb://hshy-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/app-api/hshy/**
|
||||
filters:
|
||||
- RewritePath=/app-api/hshy/v3/api-docs, /v3/api-docs
|
||||
## hrmrg-server 服务
|
||||
- id: hrmrg-admin-api # 路由的编号
|
||||
uri: grayLb://hrmrg-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/admin-api/hrmrg/**
|
||||
filters:
|
||||
- RewritePath=/admin-api/hrmrg/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v2/api-docs
|
||||
- id: hrmrg-app-api # 路由的编号
|
||||
uri: grayLb://hrmrg-server
|
||||
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
|
||||
- Path=/app-api/hrmrg/**
|
||||
filters:
|
||||
- RewritePath=/app-api/hrmrg/v3/api-docs, /v3/api-docs
|
||||
## system-server 服务
|
||||
- id: system-admin-api # 路由的编号
|
||||
uri: grayLb://system-server
|
||||
|
@ -185,6 +224,15 @@ knife4j:
|
|||
gateway:
|
||||
enabled: true
|
||||
routes:
|
||||
- name: hsfx-server
|
||||
service-name: hsfx-server
|
||||
url: /admin-api/hsfx/v3/api-docs
|
||||
- name: hshy-server
|
||||
service-name: hshy-server
|
||||
url: /admin-api/hshy/v3/api-docs
|
||||
- name: hrmrg-server
|
||||
service-name: hrmrg-server
|
||||
url: /admin-api/hrmrg/v3/api-docs
|
||||
- name: system-server
|
||||
service-name: system-server
|
||||
url: /admin-api/system/v3/api-docs
|
||||
|
@ -224,7 +272,6 @@ knife4j:
|
|||
- name: ai-server
|
||||
service-name: ai-server
|
||||
url: /admin-api/ai/v3/api-docs
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
yudao:
|
||||
|
|
Loading…
Reference in New Issue