-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Describe the bug
When Proxying to a WebSocket service in local development the socket connection can rejected by the server as the Host
and Origin
header values do not match. This Origin-limiting behaviour is recommended in RFC 6455 and is implemented in the Java websockets API and the Gorillas websocket package.
The Vite proxy is intended as a convenience for local development rather than use in production. I therefore think Vite proxy should support it out-of-the-box.
I don't have a reproduction I can share but have been able to verify that upstream socket servers that implement RFC-6455 return a 403 and this causes the Vite proxy to error on initial connection.
I'm happy to raise a PR.
Reproduction
n/a
Steps to reproduce
With a vite project that connects to a remote RFC-6455 compliant websocket server without using CORS.
Steps:
- In vite.config.ts set a ws proxy that points to the websocket server
- Run
npm start
- Open browser dev tools > network
Expected:
ws request responds with a 101 Upgrade and the socket is established
Actual:
ws request receives no response and its status is Finished
System Info
System:
OS: macOS 14.4.1
CPU: (8) arm64 Apple M2
Memory: 64.20 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.1
npm: 10.2.4
Browsers:
Chrome: 124.0.6367.93
npmPackages:
@vitejs/plugin-react: ^4.2.1 => 4.2.1
vite: ^5.2.10 => 5.2.10
Used Package Manager
npm
Logs
Click to expand!
> vite -d proxy --port 1693
VITE v5.2.10 ready in 108 ms
➜ Local: http://localhost:1693/
➜ Network: use --host to expose
➜ press h + enter to show help
vite:proxy /ws -> ws https://proxied.dev.server +63ms
5:50:22 PM [vite] ws proxy socket error:
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.