I’m building an Elixir app with an umbrella architecture which we plan to put on Fly. It has several endpoints which currently run on different ports and we plan to point different subdomains at different endpoints.
Is there a “Fly way” of routing different subdomains to the correct port? Or will it be necessary to run an nginx app in front of everything and do the top-level routing from that?
Running a proxy is your best bet on Fly.io right now. But what I’d do is add an Elixir app with an endpoint that handles proxying for you, expose that as the public service, and run the other apps privately.
If you are planning on running the child applications all in the same VM, you could also create a new child application that starts a bare-bones endpoint which does the routing to the appropriate endpoint. The big caveat with this approach is the endpoint socket declarations are intercepted in a special case which won’t work if forwarding from another plug upstream, so to support this approach you’d need to specify the socket declarations of all the other children in the child proxy app. If that is a non-starter then a proxy app in another VM which does the reverse proxy, or Nginx is the way to go as Kurt mentioned.
Using a barebones proxy endpoint in the same umbrella is something we’ve considered. Can I just clarify the caveat you explained?
If I understand this correctly, if we use phoenix channels or liveview in any of our endpoints, they must be declared in the proxy endpoint. Is that correct?
@lud-wj It’s possible there are some Fly network tricks for this. However a Docker-friendly way that would almost certainly work (at least based on lorenzomar’s requirements) is a Traefik instance. It’s a very flexible proxy system that can forward traffic based on pretty much any rules you like. I’ve not used it for ten years, but it was good then, and I expect it is still maintained.
The nice thing about doing this in Docker and not Fly config is that your local instance (run with Docker Compose) will run the same way.