zachdaniel

zachdaniel

Creator of Ash

Allow forwarded to plugs to have a callback that returns additional routes

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 :slight_smile:

Most Liked

BartOtten

BartOtten

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.

Origin: MyApp.Router
Origin: Ash.FromPlug
Origin: MyApp.RoutexBackend
Origin: CldrRoutes.Something

zachdaniel

zachdaniel

Creator of Ash

Work started here:

https://github.com/phoenixframework/phoenix/pull/6122

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.

steffend

steffend

Phoenix Core Team

I don’t see a reason against this!

Where Next?

Popular in Proposals: Ideas Top

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
marcandre
I notice that most events have bindings (e.g. phx-keyup) but not the input event. The input event is the preferred way to interact with ...
New
pinetops
LiveView is by far my favorite web tech, but a few things have been nagging me. So with all the fancy and ill advised elixir tricks I cou...
New
nocksock
LiveView has spoiled me and now I would LOVE to be able to write controllers like this: defmodule DeadViewWeb.ItemController do use De...
New
pelopo
Hi, Oficial docs got this wonderful feature to download the ePub version that we can chuck to our kindles and read it. Now we are in the...
New
AHBruns
So, LiveView 0.20 brought an async processing API which is a thin wrapper around tasks. It’s a very nice convenience, but the main thing ...
New
engineeringdept
In 2026 double submit/session tokens are no longer necessary to prevent against CSRF attacks. Instead, we can use the Sec-Fetch-Site head...
New
calebjosue
I am reading (Once more) the Phoenix web framework documentation, in the From endpoint to views section contained in the Request life-cyc...
New
Oliver
One common problem we face in constructing lists is that there is (AFAIK) no support for conditionally inserting members into list declar...
New
MatinDevs
Currently, there are ongoing discussions about enhancing Phoenix LiveView, particularly focusing on improving performance and user experi...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement