kamaroly

kamaroly

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?

Showing Posts 1 to 5

D4no0

D4no0

From the documentation of Phoenix.VerifiedRoutes:

When the Router module differs from the one passed to use Phoenix.VerifiedRoutes, such as library code, or application code that relies on multiple routers. In such cases, the router module can be provided explicitly to path/3 and url/3.

If you look above, the default global setup works with only a single router:

use Phoenix.VerifiedRoutes,
  router: AppWeb.Router,
  endpoint: AppWeb.Endpoint,
  statics: ~w(images)
LostKobrakai

LostKobrakai

This is not really global, but per module / per use call. But I don’t think there’s a way to verify routes of different routers within the same module.

D4no0

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.

adamu

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
  end

Forwarded paths in your main application router will be verified as usual,
such as ~p"/admin/users".

kamaroly

kamaroly OP

Thank you. This solves my problem.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews