Lets start by a story, I work with a team on a pretty big CMS with lots of modules. We split the cms using umbrella apps. So we have composer to manage contents, publisher to manage publications and media state, ad-ops for our ads etc.
This make sens and simplify a LOT the code understanding. Because when a new dev has to work on something, apps divide the amount of code base to be aware.
Then we face the problem of “phoenix liveview could not forward requests”. The suggestion were to create a “global router” and each “sub router” must be wrapped in a big quote. But it doesnt works very well in our case. So I create a small lib squid that create this virtual router for us (before v0.2.0).
But then I faced another problem, starting the app was slow, really slow. The more routes / routers we have, the more time it needed to start the app.
After looking in the code base of phoenix router, I found this little line phoenix/lib/phoenix/router.ex at v1.8.1 · phoenixframework/phoenix · GitHub
This line is called when by plug MyAppWeb.Router in the endpoint. And guess what? The real problem is here phoenix/lib/phoenix/router.ex at v1.8.1 · phoenixframework/phoenix · GitHub
This prevent ANY others routers to be called. And yeah I guess we could find a better way to manage NoRouteError. Without this error we could easily have something like
defmodule MyAppWeb.Endpoint do
# ... basic stuff
plug MyUmbrellaApp1.Router
plug MyUmbrellaApp2.Router
end
I tried something on squid (v0.2.0) and it works well squid/lib/squid/router.ex at main · Omerlo-Technologies/squid · GitHub .
I’m not here to talk about squid, but more to find an elegant way to fix that directly on Phoenix.
IMO the forward macro wasn’t the real problem, we stay focus on it whereas trying to understand the real problem.
Edit : the proposal is to rework a little bit the route handling of Phoenix.Router macro




















