Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change phoenix endpoint url host at runtime

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.

like image 474
Pratik Khadloya Avatar asked Nov 27 '15 06:11

Pratik Khadloya


2 Answers

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 
like image 91
Mac Avatar answered Nov 18 '22 20:11

Mac


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

like image 22
Everett Avatar answered Nov 18 '22 20:11

Everett