我有一个 Node.JS 服务器在 http://localhost:8080 运行,有 2 条路由:
"/"
:服务/public/index.html."/rest"
:返回{ ok: true }
。此服务器还在同一端口上运行 Websocket 连接。在 index.html 中,我使用 const socket = new WebSocket("ws://" + window.location.host)
连接到服务器。当我运行此服务器并访问
http://localhost:8080 时,以下内容有效:
http://localhost:8079 运行 vue-cli 应用程序,并使用以下 vue.config.js 配置:
...
devServer: {
port: 8079,
"/": {
target: "http://localhost:8080/",
ws: true
},
}
当我运行此应用程序并访问 http://localhost:8079 时,会发生以下情况:
ws: true
,它也用于代理 WebSocket 连接。