Matsa59

Matsa59

Phoenix Router Plug impl does too many things

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

Most Liked

steffend

steffend

Phoenix Core Team

Maybe a first step would be to find out what the actual proposal is. Maybe “allow routers to be chained”, which could look like this:

plug MyAppWeb.RouterA, raise_not_found: false
plug MyAppWeb.RouterB, raise_not_found: false
plug MyAppWeb.RouterC

Would that make sense?

Where Next?

Popular in Proposals: Ideas Top

azyzz228
The slow network is known to be an Achilles heel of LiveView’s architecture. Recently, I was working on creating a fast rendering map wi...
New
snofang
In a typical business development task, having a function in a context module which accepts attributes of map type and passes them to Ect...
New
GenericJam
I’ve been messing around with image generation models recently and thought this could be wrapped in a library or people could just use th...
New
mikesax
On a Rails/Turbo site, the first page is typically loaded using http GET and then sockets are used navigate and replace HTML content for ...
New
virinchi_cv
The Problem Phoenix 1.8 comes aggressively coupled with Daisy UI, a decision which many developers in the community have had mixed feelin...
New
cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New
sevensidedmarble
All the pieces are there to execute arbitrary JS commands from the server. You can put them on a data property and call them from the cli...
New
derekkraan
I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked w...
New
davydog187
I’ve been enjoying the new Streams API, but I keep needing to work around the lack of access to the underlying items. One issue that cons...
New
superchris
Currently there is no out of the box way to support DOM Custom Events in phoenix. I’ve created a separate library to do this, but I’d lov...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement