kamaroly
How to verify routes from multiple routers?
Hi all,
I am working on an application with routers separated by their domain. The application has MyApp.Expenses.Router, MyApp.Inventory.Router etc..
I have written a plug to redirect the traffic to the right router and it works well, however, Phoenix is not recognising routes outside MyAppWeb.Router as verified. When I attempted to list/ quote all the routers in the MyAppWeb.Router.verified_routes Phoenix is overriding them and only recognises the last one.
How do I achieve the verification routes located in different files?
Marked As Solved
adamu
I did something similar, and it worked out simplest to forward from one router to the other. Then everything is verified from the context of the parent router, and ~p works as expected.
It could be more prominent but the clearest docs for this are under url:
Forwarded routes are also resolved automatically. For example, imagine you
have a forward path to an admin router in your main router:defmodule AppWeb.Router do ... forward "/admin", AppWeb.AdminRouter end defmodule AppWeb.AdminRouter do ... get "/users", AppWeb.Admin.UserController endForwarded paths in your main application router will be verified as usual,
such as~p"/admin/users".
Also Liked
D4no0
Makes sense, even though by default this option is defined in MyAppWeb, so some structural changes of your phoenix project are in order for this.
I would rather use the path/3 and url/3 option from a helper macro/macros that I could easily define and import in MyAppWeb.
kamaroly
Last Post!
kamaroly
Popular in Questions
Other popular topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









