6
votes

Does anyone know of a way of changing the :host of the Phoenix application endpoint dynamically on every request?

Specifically to support multiple domains on a single phoenix app, i want to change the host in the endpoint based on the host in the connection object.

Am trying something on the lines of

conn = Map.get_and_update(conn.private.phoenix_endpoint[:url], :host, fn (_) -> "ll.com" end)

or

Keyword.put(conn.private.phoenix_endpoint.config(:url), :host, conn.host)

But am not quite correct.

2
Is changing conn.host (using e.g. conn = %{conn | host: "ll.com"}) not enough for your use case? - Dogbert
That does not change the host in the redirects. - Pratik Khadloya

2 Answers

1
votes

Wouldn't it just be a value you assign the :to keyword in the redirect?

def index(conn, params) do
  redirect conn, to: params[:location] # or whatever
end 
1
votes

The master_proxy package offers some useful tools to support multiple sites.