hauleth
Define root path per router instead on endpoint level only
I am building application where I have separate routers for each part of the API (REST, UI, and GraphQL):
defmodule MyApp.Router do
use Phoenix.Router
forward("/graphql", MyApp.GraphQL.Router)
forward("/api", MyApp.REST.Router)
forward("/", MyApp.UI.Router)
end
Currently there is no problem with that as I can specify “sub-path” in API documentation (OpenAPI), but I see potential problem in future where the amount of routers can grow. Namely imagine situation where I would need to add new router, ex. MyApp.Foo.Router within scope /foo but within that controller I would need it to generate paths with that prefix, so I will need to workaround that by either remember to provide handcrafted %URL{} as the first parameter to the helper functions or to write it as /foo/<%= helper_path(…) %> (that second option will not work for other helpers though). What I would love to see is option :path similar to the Phoenix.Endpoint one passed either to Phoenix.Router.__using__/1 or (even better) to generated Router.init/1. That second option is even better as it allows me to define used route in the same place I define forwarding.
What are your opinions on such feature? Or maybe I missed something that is already possible.
First Post!
nivanson
I don’t know how to get rid of the routing issue for your solution. For this specific problem I think having separate endpoints with a master proxy is an acceptable solution. One can define an endpoint that proxies the others based on whatever logic you want. Domain. Route. Whatever. See this example.
https://github.com/wojtekmach/acme_bank/blob/master/apps/master_proxy/lib/master_proxy/plug.ex
Popular in Questions
Other popular topics
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
- #api
- #forms
- #metaprogramming
- #security
- #hex










