leonardorame
How to configure Apache ProxyPass and LiveView?
Hi, my LiveView route is this:
scope "/api", MultiTWeb do
pipe_through [:api, :browser]
live "/:client_uuid/pacientes", EntregaDigitalLive.IndexLive
end
So, going to http://localhost:4003/api/5a1e8e63-e5ce-42f7-ba6c-0de82e2bc587/pacientes works correctly. Then I set up an Apache ProxyPass rule this way:
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) "ws://127.0.0.1:4003/$1" [P,L]
ProxyPass /api http://127.0.0.1:4003/api
ProxyPassReverse /api http://127.0.0.1:4003/api
This works:
https://example.com/api/5a1e8e63-e5ce-42f7-ba6c-0de82e2bc587/pacientes
Now as this is a multi tennant app I would like to let the user go here:
https://example.com/pacientes
And configure Apache to go to http://127.0.0.1:4003/api/5a1e8e63-e5ce-42f7-ba6c-0de82e2bc587/pacientes:
To do this I just added this ProxyPass directive:
ProxyPass /pacientes http://127.0.0.1:4003/api/5a1e8e63-e5ce-42f7-ba6c-0de82e2bc587/pacientes
Now, if I go to https://example.com/pacientes the page opens correctly, but immediately the websocket crashes giving this error (in Firefox’s developer’s tools → network):
["4","4","lv:phx-GAwVwpiVCAMFmZFx","phx_reply",{"status":"error","response":{"reason":"join crashed"}}]
Also in the Iex console I get:
08:52:26.194 [error] GenServer #PID<0.27095.0> terminating
** (FunctionClauseError) no function clause matching in MultiTWeb.EntregaDigitalLive.IndexLive.mount/3
(multi_t 0.1.0) lib/multi_t_web/live/entrega_digital_live/index_live.ex:7: MultiTWeb.EntregaDigitalLive.IndexLive.mount(:not_mounted_at_router, %{"_csrf_token" => "VMwaQsqDYHjXnzXxXRP_OO
PM", "live_socket_id" => "users_sessions:zAroyFVodPFvRp1DZkqqW9_K0fz2gbee4CIajR4Vx5Q=", "user_token" => <<204, 10, 232, 200, 85, 104, 116, 241, 111, 70, 157, 67, 102, 74, 170, 91, 223, 202,
209, 252, 246, 129, 183, 158, 224, 34, 26, 141, 30, 21, 199, 148>>}, #Phoenix.LiveView.Socket<id: "phx-GAwV0UtJEVN__ZHR", endpoint: MultiTWeb.Endpoint, view: MultiTWeb.EntregaDigitalLive.Ind
exLive, parent_pid: nil, root_pid: #PID<0.27095.0>, router: MultiTWeb.Router, assigns: %{flash: %{}, __changed__: %{}, live_action: nil}, transport_pid: #PID<0.27092.0>, ...>)
Why this works:
https://example.com/api/5a1e8e63-e5ce-42f7-ba6c-0de82e2bc587/pacientes
and this not?:
https://example.com/pacientes
First Post!
leonardorame
I still can’t figure out how to fix this, but I found the websocket’s response has the url parameter exactly as the browser’s url, while it should be the internal app url.
Does anyone know how to force this in Apache?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








