How to list all routes in an Elixir / Plug project without Phoenix

I know Phoenix has mix phx.routes and Phoenix.Router.routes(), but I’ve been researching for a bit and couldn’t find any information or pointer towards how to achieve the same result without Phoenix. Does anyone have any insight into how this could be done?

Phoenix can only do so because it tracks routes registered in a use Phoenix.Router router. There’s no such tracking for plain plugs (as they’re middleware not routes) and afaik Plug.Router also doesn’t expose anything similar, it likely could be added to it though.

1 Like

Phoenix routes are made using macro calls. Those macro calls, among other things such as defining a plug clause, create a map of all routes which is used when you print the route table.

You could write your own macro to mimic this behavior, although not sure if that’s worth the trouble.

Short example in ‘write_routes/2’

1 Like