wojtekmach / acme_bank

An example ☂ project
MIT License
756 stars 103 forks source link

Websocket unable to connect between proxied apps and client using Master proxy #14

Closed iampeterbanjo closed 5 years ago

iampeterbanjo commented 7 years ago

Using the boilerplate "hello" app an the Phoenix guides site and the master proxy in this application I am seeing the following errors on my websocket connections:

[info] GET /phoenix/live_reload/socket/websocket
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /phoenix/live_reload/socket/websocket (HelloWeb.Router)
    (hello) lib/hello_web/router.ex:1: HelloWeb.Router.__match_route__/4
    (hello) lib/phoenix/router.ex:303: HelloWeb.Router.call/2
    (hello) lib/hello_web/endpoint.ex:1: HelloWeb.Endpoint.plug_builder_call/2
    (hello) lib/plug/debugger.ex:99: HelloWeb.Endpoint."call (overridable 3)"/2
    (hello) lib/hello_web/endpoint.ex:1: HelloWeb.Endpoint.call/2
    (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
    (cowboy) /media/iampeterbanjo/data/programs/elixir/portfolio/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

The endpoint for the hello app are boilerplate:

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

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
  end

Since there is only one app at the moment, my proxy plug.ex is:

defmodule Proxy.Plug do
  def init(options) do
    options
  end

  def call(conn, _opts) do
    cond do
      false ->
        HelloWeb.Endpoint.call(conn, [])
      true ->
        HelloWeb.Endpoint.call(conn, [])
    end
  end
end

This happens when I start the phoenix web server for the umbrella app and not the sub-app. A repo of my code is at https://github.com/iampeterbanjo/hello-proxy

Is there a way to proxy the websockets as well in the master proxy?

jesuisbonbon commented 7 years ago

did you manage to fix this?

iampeterbanjo commented 7 years ago

No I haven't. I had to use a reverse proxy and pass through the "Upgrade" header.

Sent from my Motorola Moto G (5) Plus using FastHub

janpieper commented 7 years ago

Would be cool to see a fix!

obsidienne commented 6 years ago

Hi,

This thread on elixir forum seems to resolve the issue: https://elixirforum.com/t/phoenix-1-3-umbrella-architecture/4100/11

I didn't had the time to check it.

iampeterbanjo commented 6 years ago

thanks @obsidienne - I've added a comment to that thread but I don't think it answers the question. The thread seems to be unresolved. Please let me know if I have missed something.

cblavier commented 5 years ago

I struggled with master_proxy but finally made it work on my Phoenix 1.4 / cowboy 2.5 app.

It supports HTTPS and websockets properly, here is a gist: https://gist.github.com/cblavier/0c2cf3f101d82c32503774f179a66a3f

iampeterbanjo commented 5 years ago

@cblavier thanks for sharing - that looks promising. does it work for the static assets? e.g. do the favicons, images etc in the apps appear correctly without showing errors in the browser console?

cblavier commented 5 years ago

Yes, it's working for my js / css bundles, and my favicon / robot.txt as well

iampeterbanjo commented 5 years ago

@cblavier brilliant! i'll try it out. I'll close this issue then. Thanks a bunch.