The socket does not connect to the endpoint

var socket = new Socket("localhost:4000")
socket.connect()

Returns WebSocket connection to 'ws://localhost:4000/ws' failed: Error during WebSocket handshake: Unexpected response code: 404

But I have a socket on the endpoint /ws, right?

defmodule Sapphire.Endpoint do
  use Phoenix.Endpoint, otp_app: :sapphire

  socket "/ws", Sapphire.MomentSocket

  plug Plug.Static,
    at: "/", from: :sapphire, gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt)

  if code_reloading? do
    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
  end

  plug Plug.RequestId
  plug Plug.Logger

  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Poison

  plug Plug.MethodOverride
  plug Plug.Head

  plug Plug.Session,
    store: :cookie,
    key: "_sapphire_key",
    signing_salt: "hW1bFEcR"

  plug Sapphire.Router

end

He should be able to connect to this endpoint, but for some reason he cannot reach it at all.

[info] Running Sapphire.Endpoint with Cowboy on http://localhost:4000

+4
source share
2 answers

@Jose Valim found a solution.

I ported the phoenix.js library to coffeescript and overlooked the fact that the path suffix should be any transport layer. In this case, he needed the /websocketend of implementation. :)

+4
source

Full disclosure - I'm noob, and I probably messed up something, but so I got back on the right track.

rm -rf deps/phoenix

This will clear your current version of phoenix (which includes phoenix.js)

mix do deps.get

.

, , - , , mac/linux, a:

find . -name phoenix.js

Voila, phoenix.js, . phoenix.js, .

0

Source: https://habr.com/ru/post/1608105/


All Articles