reverend_paco

reverend_paco

Phoenix LiveView Websocket proxy and live_redirect

I am deploying an Elixir application behind an Nginx proxy (multiple Elixir applications actually) and am having some issues specific (I think) to live_redirect.

I have

  1. changed the url in my config.exs by adding the path as such: url: [host: "localhost", path: "/campaign"]
  2. prepended the base-url to the app.js as such: let liveSocket = new LiveSocket("/campaign/live", Socket, {params: {_csrf_token: csrfToken}})

I have another application that uses LiveView that works fine, but this campaign application, which another developer has developed, manifests the problems.

In the backend I see:

[error] an exception was raised:
    ** (ArgumentError) cannot invoke handle_params nor live_redirect/live_link to "https://[ELIDED]/campaign/dashboard/nonode%40nohost" because it isn't defined in CampaignsLiveWeb.Router
        (phoenix_live_view 0.12.1) lib/phoenix_live_view/utils.ex:209: Phoenix.LiveView.Utils.live_link_info!/3
        (phoenix_live_view 0.12.1) lib/phoenix_live_view/channel.ex:600: Phoenix.LiveView.Channel.verified_mount/4
        (phoenix_live_view 0.12.1) lib/phoenix_live_view/channel.ex:34: Phoenix.LiveView.Channel.handle_info/2

I am wondering if anyone has seen anything similar to this before, and can give me a hint as to where I might explore?

Again, I have successfully deployed another LiveView application using the above 2 points, so I know that nginx is properly passing/upgrading the websockets. I feel that this is related to the issue here, although in my case, I know what the top-level URL is going to be and am not using dynamic re-writing.

Thanks,
Daniel

Marked As Solved

reverend_paco

reverend_paco

Well, my hack worked. I changed utils.ex and channel.ex and static.ex to pass in the endpoint to the live_link_info and then used the path to remove the prefix coming in from websocket and things started working.

Feeling proud of myself, I wanted to see if I could contribute it back and checked on github and saw that this has been fixed with the following patch: Consider script_name on client URLs, closes #805 · phoenixframework/phoenix_live_view@06b3e81 · GitHub

So if anyone is having a similar problem, grab the latest from master (I was on version 0.12.0)

EDIT: if you don’t want master, it looks like this fix is on 0.13.0

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement