I'm not sure which is the best method.
But something like this is possible as an illustration inside the IndexController .
def index(conn, params) do url_with_port = Atom.to_string(conn.scheme) <> "://" <> conn.host <> ":" <> Integer.to_string(conn.port) <> conn.request_path url = Atom.to_string(conn.scheme) <> "://" <> conn.host <> conn.request_path url_phoenix_helper = Tester.Router.Helpers.index_url(conn, :index, params["path"]) # <-- This assumes it is the IndexController which maps to index_url/3 url_from_endpoint_config = Atom.to_string(conn.scheme) <> "://" <> Application.get_env(:my_app, MyApp.Endpoint)[:url][:host] <> conn.request_path url_from_host_header = Atom.to_string(conn.scheme) <> "://" <> (Enum.into(conn.req_headers, %{}) |> Map.get("host")) <> conn.request_path text = ~s""" url_with_port :: #{url_with_port} url :: #{url} url_phoenix_helper :: #{url_phoenix_helper} url_from_endpoint_config :: #{url_from_endpoint_config} url_from_host_header :: #{url_from_host_header} """ text(conn, text) end
stephen_m
source share