Configuring the websocket proxy interface address in vue-cli does not work

configuration file:

dev: {

env: require("./dev.env"),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: "static",
assetsPublicPath: "/",
proxyTable: {
    "/risk":{
        target:"http://xxx.xxx.xxx.xxx/"
    },
    "/socket": {
        target:"ws://xxx.xxx.xxx.xxx/",
        ws: true,
    }
} 

var ws = new WebSocket ("/ socket/xxx")

there is no problem directly using var ws = new WebSocket ("ws://xxx.xxx.xxx.xxx/socket/xxx"). When configuring the proxy address, the interface in the" / risk" path is normal, and the / socket interface reports an error
Uncaught DOMException: Failed to construct "WebSocket": The URL" / socket/xxx" is invalid.


var ws = new WebSocket ('ws://' + location.host +' / socket/xxx')


the proxy is set like the landlord, but when using var ws = new WebSocket ('ws://' + location.host +' / socket/xxx'), there is always an error
WebSocket connection to 'ws://xxx.xxx.xxx.xxx/socket/xxx' failed: Connection closed before receiving a handshake response.
does the landlord know how to solve the problem?


I have the same question. Which god will give us some advice

?
Menu