SpringCloudGateWay转发websocket请求

428 阅读1分钟

在使用websocket推送消息时,因为涉及到了鉴权,走了一遍gateway,调试过程中遇到了几个问题,因此记录一下

- id: websocket
  predicates:
    - Path=/socket.io/**
  uri: ws://be-base-push:9000

QA

Q: 400 BAD_REQUEST "Invalid 'Upgrade' header
A: 需要在前端的websocket的配置中设置 transport:[websocket],不能使用polling
Q: org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponse
A: gateway项目中引用了taomcat相关的包,排除或删掉
Q: namespace和路径的设置
A: [参考链接](Client options | Socket.IO) e.g:

import { io } from "socket.io-client";
const socket = io("https://example.com/order", {
  path: "/my-custom-path/"
});
``