我正在尝试将我的前端与 Phoenix 1.3 (localhost:4000) 分开,并且我正在 localhost:3000 上运行 React。
我终生无法与凤凰城联系。我得到错误:
WebSocket connection to 'ws://localhost:4000/socket/websocket?token=undefined&vsn=2.0.0' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
我正在使用以下客户端:
let socket = new Socket("ws://localhost:4000/socket", {params: {token: window.userToken}})
socket.connect();
// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("coin:lobby", {});
channel
.join()
.receive("ok", resp => {
console.log("Joined successfully", resp);
})
.receive("error", resp => {
console.log("Unable to join", resp);
});
我可以设法在终端中使用 wsta 进行连接,并且收到了很好的响应。我认为这可能是某种 CORS 问题,但我已经实现了cors_plug
elixir 库,但我仍然遇到问题。有什么建议吗?