Skip to content
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

Websocket connection not done to the right host #460

Closed
Grafikart opened this issue Jun 25, 2020 · 3 comments
Closed

Websocket connection not done to the right host #460

Grafikart opened this issue Jun 25, 2020 · 3 comments

Comments

@Grafikart
Copy link

Describe the bug

I'm currently trying to use vite to serve assets for a backend generated site.
The site is available on http://localhost:8000
Vite is server on http://localhost:3000

ws is established using ws://localhost:8000 instead of ws://localhost:3000

Reproduction

If you inspect /vite/hmr you find this line :
const socket = new WebSocket(${socketProtocol}://${location.host});

System Info

  • vite version:
  • Operating System: any
  • Node version: any

Suggestion / Solution

Could the websocket path using the port / location from vite dev server ?
In the meantime this issue can be solved using a koah middleware

    app.use(async (ctx, next) => {
      await next();
      if (ctx.url === '/vite/hmr') {
          ctx.response.body = ctx.response.body.replace('${socketProtocol}://${location.host}', '${socketProtocol}://localhost:3000')
      }
    })
@yyx990803
Copy link
Member

Seems to be the same use case for #452?

@Grafikart
Copy link
Author

@yyx990803 the issue is pretty close but a bit different, the goal here is not to run ws on a different port / host but having the connection done to the right host / port. Feel free to merge the issue if you think it's the same problem.

underfin pushed a commit to rolldown/vite that referenced this issue Jul 4, 2020
Allows assets to be served under a different port
close vitejs#452, close vitejs#460
@edersoares
Copy link
Contributor

@Grafikart can you see this approach #918? Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants