Umbrella with 2 phoenix apps, how to forward request from 1 to 2 and vice versa

Two phoenix apps need to listen on two distinct ports. If you’re trying to incorporate an admin site for your main app, you could consider one app with one endpoint and special handling based on the hostname used to access the site.

You could make a helper plug like:

defmodule Host do
  @behaviour Plug

  def init(hosts), do: hosts

  def call(conn, hosts) do
    plug_mod = Map.fetch!(hosts, conn.host)
    plug_mod.call(conn, plug_mod.init(nil))
  end
end

And then immediately in your endpoint you could do the switch:

plug Host, %{
  "mysite.com" => SitePlug,
  "admin.mysite.com" => AdminPlug
}

You’d need to move endpoint plugs to the plug modules which would be based on Plug.Builder

Standard disclaimers apply :slight_smile:

2 Likes