vue-cli icon indicating copy to clipboard operation
vue-cli copied to clipboard

Websocket connection failed, Invalid frame header

Open dean5277 opened this issue 8 years ago • 16 comments

Version

3.0.0-rc.3

Reproduction link

http://localhost:8080

Steps to reproduce

npm run serve

What is expected?

no error

What is actually happening?

when i run dev serve, brower console print socket error. image image

dean5277 avatar Jul 14 '18 10:07 dean5277

You seem to be messing with the proxy with this proxyfile? But you don't share it.

We can't investigate you report without a proper, run able reproduction (as a guy repository)

Please provide one or we have to close this issue.

LinusBorg avatar Jul 14 '18 11:07 LinusBorg

image

proxyFile content.

dean5277 avatar Jul 14 '18 11:07 dean5277

That's not a run able reproduction. I won't type the code from your screenshot to run it.

LinusBorg avatar Jul 14 '18 11:07 LinusBorg

I am running into this issue too. Basically, when the / path exist, HMR websocket requests are not ignored and will be somehow proxied. This can be disabled by adding ws: false to the options, however, this will disable all websocket requests.

rayax86 avatar Jul 27 '18 07:07 rayax86

I am running into this issue too

tomwang1013 avatar Aug 22 '18 02:08 tomwang1013

+1

yhshen93 avatar Sep 05 '18 01:09 yhshen93

proxytable key 'ws' set false, this will disable all websocket requests.

dean5277 avatar Sep 05 '18 11:09 dean5277

In my case, I use the following configuration to proxy websocket for my site:

proxys: {
  '/websocket': {
    target: my_ws_server,
    ws: true,
    changeOrigin: true
  }
}

It will cause the same problem like the issue said.

All what I do to resolve is to add a '^' :

proxys: {
  '^/websocket': {
    target: my_ws_server,
    ws: true,
    changeOrigin: true
  }
}

yhshen93 avatar Sep 27 '18 06:09 yhshen93

@ChrisShen93 Cool, in which package does the ^ actually took effect?

rayax86 avatar Sep 27 '18 06:09 rayax86

@rayax86 Sorry for late reply. That's for the http-proxy-middleware.

yhshen93 avatar Oct 03 '18 13:10 yhshen93

ws改为false

cduyzh avatar Mar 20 '19 03:03 cduyzh

Why set it to ws: false, it works?

tangdaohai avatar Nov 29 '19 08:11 tangdaohai

running vue-cli itself will run a websocket service on /ws route, e.g. ws://127.0.0.1:8080/ws to do live reload and other vue-cli internal services.

if you use same route for your app and try to proxy it, there will be a conflict. you can simply try to use another route to avoid this conflict. I couldn't fix it with ^/ws or ws: true/false, but rename the route to something else simply solved the issue.

'/websock': {
    target: 'http://127.0.0.1:8000',
    changeOrigin: true,
    ws: true,
},

gowhari avatar Sep 22 '22 13:09 gowhari

The reason is that the path of webSocketServer conflicts with the path of proxy in the project. It can be solved by modifying the path of webSocketServer.

  devServer: {
    webSocketServer: {
      options: {
        path: "/yourCustomPath"
      }
    }
  }

Lucas-lgm avatar Jan 19 '23 13:01 Lucas-lgm

In my case , I am using http-proxy-middleware, I updated the proxy configuration from:

    app.use(
        '/hubs',
        createProxyMiddleware({
            target: 'your target url',
            changeOrigin: true,
            ws: true
        })
    );

to

   app.use(
        createProxyMiddleware('/hubs', {
            target: 'your target url',
            changeOrigin: true,
            ws: true
        })
    );

Then the issue is fixed.

LiMeii avatar Jan 20 '23 16:01 LiMeii

based on @liangguangming solution but for the people that are still using webpack 4.x :-)

devServer: {
    sockPath: '/webpack-dev',
}

https://v4.webpack.js.org/configuration/dev-server/#devserversockpath

gowhari avatar May 02 '23 18:05 gowhari