最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Not able to run socket.io behind proxy. Cannot GET socket.io 404 - Stack Overflow

programmeradmin3浏览0评论

I am trying to run socket.io behind a Node.js proxy as explained here:

const WS_TARGET = 'ws://localhost:8080'; // Upstream WebSocket server
const wsProxy = createProxyMiddleware({
  target: WS_TARGET,
  ws: true,  // Enable WebSocket proxying
  changeOrigin: true,
  logLevel: 'debug'
});
const app = express();
app.use('/chat', wsProxy)

in my client I have:

const socket = io("http://localhost:3000/chat")

but when I run the client I get a stream of:

2025-03-10 17:59:04:594 warn: GET /socket.io/?EIO=4&transport=polling&t=s9lrd5zc ::ffff:127.0.0.1 - 0.423 ms 404
2025-03-10 17:59:09:599 warn: GET /socket.io/?EIO=4&transport=polling&t=s9pmr8yv ::ffff:127.0.0.1 - 0.212 ms 404
2025-03-10 17:59:14:5914 warn: GET /socket.io/?EIO=4&transport=polling&t=s9ti1i74 ::ffff:127.0.0.1 - 0.101 ms 404

I have put a working demo here and a video of what I see here

发布评论

评论列表(0)

  1. 暂无评论