修改配置
This commit is contained in:
parent
13db8a2600
commit
2597f02517
|
|
@ -9,6 +9,8 @@ import org.springframework.context.annotation.Configuration;
|
|||
/**
|
||||
* Gateway 路由配置
|
||||
* 配置 WebSocket 转发规则
|
||||
*
|
||||
* 注意:路由配置已移至 application.yml,此 Java 配置已禁用以避免冲突
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
|
|
@ -16,20 +18,21 @@ public class GatewayConfig {
|
|||
|
||||
/**
|
||||
* 配置路由规则
|
||||
* 将 /ws/api/** 转发到 ws://iot.t-aaron.com:18080/api/**
|
||||
* 将 /api/ws/** 转发到 ws://iot.t-aaron.com:18080/api/ws/**
|
||||
*
|
||||
* 此配置已注释,使用 application.yml 中的配置
|
||||
*/
|
||||
@Bean
|
||||
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
.route("websocket-route", r -> r
|
||||
.path("/ws/api/**")
|
||||
.filters(f -> f
|
||||
.stripPrefix(1) // 移除 /ws 前缀
|
||||
.filter(new com.tuoheng.gateway.filter.WebSocketFilter().apply(
|
||||
new com.tuoheng.gateway.filter.WebSocketFilter.Config()))
|
||||
)
|
||||
.uri("ws://iot.t-aaron.com:18080")
|
||||
)
|
||||
.build();
|
||||
}
|
||||
// @Bean
|
||||
// public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
|
||||
// return builder.routes()
|
||||
// .route("websocket-route", r -> r
|
||||
// .path("/api/ws/**")
|
||||
// .filters(f -> f
|
||||
// .filter(new com.tuoheng.gateway.filter.WebSocketFilter().apply(
|
||||
// new com.tuoheng.gateway.filter.WebSocketFilter.Config()))
|
||||
// )
|
||||
// .uri("ws://iot.t-aaron.com:18080")
|
||||
// )
|
||||
// .build();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ spring:
|
|||
- id: websocket-route
|
||||
uri: ws://iot.t-aaron.com:18080
|
||||
predicates:
|
||||
- Path=/ws/api/**
|
||||
- Path=/api/ws/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- name: WebSocketFilter
|
||||
|
||||
# 启用 JWT 认证(默认为 false,即不启用)
|
||||
|
|
|
|||
Loading…
Reference in New Issue