Importing a Phoenix app as a dependency in another phoenix app in an umbrella project... Please any advice?

I have two Phoenix web app in an umbrella project: admin and front. I will probably add another web app blog soon.

I added :front app as a dependency in the :admin app so I can generate urls to the “Front website”. This work fine as long as I start the Phoenix server ever:

  1. only from the admin app root
  2. only from the front app root
  3. or from the umbrella project root

In the last case both apps are available in the browser at http://localhost:4000/ and http://localhost:4001/. If I try to start the apps separetely, the last I try to start will fail with the following error:

03:48:13.459 [error] Failed to start Ranch listener Front.Endpoint.HTTP in :ranch_tcp:listen([cacerts: :…, key: :…, cert: :…, port: 4000]) for reason :eaddrinuse (address already in use)

So I vaguely understand that there is something like a listening conflict on a port?

But when starting the server from the umbrella perpective, put in simple words, why is it working?

And more importantly should I be aware of a potential issue in the future? I mean as long as it’s ok for me not to deploy the apps separately.


You say that one app depends on the other, so if you start that app, it will also try to start the other. Though if you have the other already up and running in another BEAM instance, then of course that port will already be in use.

It should be enough to start the app that depends on the other, to access both applications, or to start from the umbrella.


Oh, that’s right!

I just noticed that this is indeed what was happening. And I can access the Front site directly, just by launching the Admin site. Fantastic and thank you! ^^

Wait, if you start two phoenix on the same port on the same BEAM instance, there is not conflict about port ?

Doesnt’t both phoenix apps try to start they own ranch listener ?

edit: Nevermind, I missed the 4000/4001 part :smiley:

When you start two apps on the same port, then there will be a conflict.

Though in this scenario, both applications started their HTTP server on different ports, 4000 and 4001.