MainProxy - Run multiple Phoenix apps on one port

Note: previously the name of this library was MasterProxy

I just released version 0.2.0 of MainProxy. If you ever want to run multiple Phoenix Endpoints or Plugs from a single HTTP(S) port without manually writing a cowboy handler than MainProxy is for you!

To define your own proxy you add {:main_proxy, "~> 0.2"} to your deps, then create a proxy module:

defmodule MyApp.Proxy do
  use MainProxy.Proxy

  @impl MainProxy.Proxy
  def backends do
    [
      %{
        domain: "my-cool-app.com",
        phoenix_endpoint: MyCoolAppWeb.Endpoint
      },
      %{
        domain: "members.my-cool-app.com",
        phoenix_endpoint: MyAppMembersWeb.Endpoint
      }
    ]
  end
end

And then add MyApp.Proxy to your supervision tree in (usually in application.ex) and you can now serve multiple domains from one BEAM instance!

I’m interested in MainProxy because I run multiple applications from one BEAM instance with it:

And I’d like to give a big thanks to @jesse who created the initial version of the library :heart:

15 Likes