http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

Websocket only works on initial protocol

Open Netail opened this issue 2 months ago • 0 comments

Checks

Describe the bug (be clear and concise)

It seems that the proxy (websocket) only works on the protocol of the first request.

If a proxy endpoint (the initial request) is first visited with the ws protocol, the proxy will only work on ws. If you first visit on wss, the proxy will only work on wss.

So if the initial request was on the ws protocol, the proxy won't resolve a response on wss and keeps in the "connecting" state as it keeps waiting for a response from the proxy. This can also be performed the other way around. First wss then ws

Step-by-step reproduction instructions

1. `npm install`
2. `npm run dev`
3. Visit `ws://localhost:3000/`, it will successfully proxy to the websocket server
4. Visit `wss://localhost/`, it will fail to resolve a response

Repro: https://github.com/Netail/repro-http-proxy-websocket

Expected behavior (be clear and concise)

Proxy should work on both protocols or at least resolve a response

How is http-proxy-middleware used in your project?

[email protected] <root>\repro-http-proxy-websocket
└── [email protected]

What http-proxy-middleware configuration are you using?

https://github.com/Netail/repro-http-proxy-websocket/blob/main/proxy.ts

What OS/version and node/version are you seeing the problem?

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz       
    Memory: 20.45 GB / 31.93 GB
  Binaries:
    Node: 22.20.0
    npm: 11.5.2
    pnpm: 10.15.1
    bun: 1.2.20

Additional context (optional)

No response

Netail avatar Oct 10 '25 20:10 Netail