From 16941acb0f5fd15fe4627f6fabe20f0f93ff9724 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 18 Apr 2024 21:47:02 +0200 Subject: [PATCH] Refactor presenter module to use endpoint configuration --- lib/claper_web/live/event_live/presenter.ex | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/claper_web/live/event_live/presenter.ex b/lib/claper_web/live/event_live/presenter.ex index b7ed9240..67ca89e5 100644 --- a/lib/claper_web/live/event_live/presenter.ex +++ b/lib/claper_web/live/event_live/presenter.ex @@ -33,16 +33,24 @@ defmodule ClaperWeb.EventLive.Presenter do ) end - host = - case get_connect_params(socket) do - nil -> "" - %{"host" => host} -> host - end + endpoint_config = Application.get_env(:claper, ClaperWeb.Endpoint)[:url] + port = endpoint_config[:port] + scheme = endpoint_config[:scheme] + host = endpoint_config[:host] + path = endpoint_config[:path] + + default_ports = [80, 443] + port_suffix = if port in default_ports, do: "", else: ":" <> Integer.to_string(port) + + host = "#{scheme}://#{host}#{port_suffix}/#{path}" socket = socket |> assign(:attendees_nb, 1) - |> assign(:host, host) + |> assign( + :host, + host + ) |> assign(:event, event) |> assign(:state, event.presentation_file.presentation_state) |> assign(:posts, list_posts(socket, event.uuid))