-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dev): modify websocket client port #1926
Conversation
@ygj6 #1925 did you try using https://vitejs.dev/config/#server-hmr config options first? From looking at the code - HMR_PORT is controlled by config.server.hmr.port
|
Good. This config can solve problem in this case. |
If you still want to go through the reverse proxy on port 3000, wouldn't you just use the same port for both server and server.hmr and just make sure the hmr.protocol : "wss" and hmr.host is set to what ip/host you are connecting to? |
This PR would solve my use case: |
Implementing this change would enable a dev server proxy middleware for ASP.NET Core. Because the port chosen for the dev server is dynamic, a config file option is not really an appropriate solution. Additionally, the Vite.js dev server may not be running with HTTPS enabled when the reverse proxy is. A fully “relative” WebSocket would solve all this and make the HMR host/port option obsolete. |
packages/vite/src/client/client.ts
Outdated
@@ -15,7 +15,7 @@ console.log('[vite] connecting...') | |||
// use server configuration, then fallback to inference | |||
const socketProtocol = | |||
__HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws') | |||
const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}` | |||
const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${location.port}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${location.port}` | |
const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__ || location.port}` |
Think this could be better. Respect server.hmr.port
if specified explicitly or use the same port as client. clientInject.ts
file needs to be changed accordingly.
…itejs#2621) Co-authored-by: Anthony Fu <[email protected]>
close #1925
Modify client websocket port from
__HMR_PORT__
tolocation.port
.Websocket client will connect to frontend port instead of backend port when there is a reverse proxy.