Something we do in various Ash packages is provide routes that the user forwards to in their own application. This is because we are deriving routes based on other configuration, and we don’t want to make the router have a compile time dependency on the modules that we are deriving this from. By separating them in this way, we keep the router clean.
However, this also means the routes from our router do not show up in mix phx.routes. We also don’t necessarily want to define sub-phoenix routers (which I’m not sure would be supported anyway) because in some cases we do runtime matching or extra logic in a Plug.Router). So my proposal is this:
When displaying routes (Phoenix.Router.ConsoleFormatter), if the plug implements a behaviour, like Phoenix.PlugWithRoutes, we will call it to return additional routes. Those routes must be returned in Phoenix’s existing format, meaning they will inherit the formatting provided by Phoenix.
This is a pretty simple thing to add and allows all of our generated routes to be displayed in-line on the dev not-found error page, and when running mix phx.routes.
If the Phoenix team is into this, I will work up a PR
I know there are at least two other packages that do that.
Maybe we can add a field to the Route struct to make clear the route is derived -and from what- and also show this in mix routes (hence the extra field instead of using metadata)? This way the origin is explicit.
In the interest of keeping it light weight, I didn’t track any special “origin” or “source”, but the source plug itself is available in the routes which should provide enough info. I did add a label field for arbitrary route labels being generated.