提交 9715a753 authored 作者: 吕本才's avatar 吕本才

feat(gateway): add WebSocket routing configuration

- Added WebSocket route with path /ws/** - Configured URI to load balance to wangxiaolu-promotion-service - Implemented path rewrite from /ws/{segment} to /websocket/{segment} - Specified protocol as websocket in metadata - Applied configuration to both live and master profiles
上级 293e59f0
......@@ -29,5 +29,20 @@ spring:
# uri: http://127.0.0.1:8011
predicates:
- Path=/**
# 2025年12月01日21:27:34 WebSocket 路由配置
- id: websocket_route
# 后端 WebSocket 服务的地址(lb:// 表示从注册中心发现服务,如 Nacos/Eureka)
# uri: lb://websocket-service # 服务名:websocket-service
uri: lb://wangxiaolu-promotion-service
# 匹配前端请求的路径(如前端连接 ws://gateway:8080/ws/123,会被转发)
predicates:
- Path=/ws/**
# 配置过滤器(可选,如路径重写)
filters:
# 将前端请求路径 /ws/{userId} 重写为后端服务的 /websocket/{userId}
- RewritePath=/ws/(?<segment>.*), /websocket/$\{segment}
# 关键:指定协议为 websocket(默认是 http,必须显式声明)
metadata:
protocol: websocket
logging:
config: classpath:logback-spring.xml
\ No newline at end of file
config: classpath:logback-spring.xml
......@@ -29,5 +29,20 @@ spring:
# uri: http://127.0.0.1:8011
predicates:
- Path=/**
# 2025年12月01日21:27:34 WebSocket 路由配置
- id: websocket_route
# 后端 WebSocket 服务的地址(lb:// 表示从注册中心发现服务,如 Nacos/Eureka)
# uri: lb://websocket-service # 服务名:websocket-service
uri: lb://wangxiaolu-promotion-service
# 匹配前端请求的路径(如前端连接 ws://gateway:8080/ws/123,会被转发)
predicates:
- Path=/ws/**
# 配置过滤器(可选,如路径重写)
filters:
# 将前端请求路径 /ws/{userId} 重写为后端服务的 /websocket/{userId}
- RewritePath=/ws/(?<segment>.*), /websocket/$\{segment}
# 关键:指定协议为 websocket(默认是 http,必须显式声明)
metadata:
protocol: websocket
logging:
config: classpath:logback-spring.xml
\ No newline at end of file
config: classpath:logback-spring.xml
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论