Hey all! Just ran into a small considering that I don’t have a good answer for.
I’m building an application that uses Absinthe and I’d like to expose its GraphiQL interface. One fun aspect of this is that any external traffic to this application’s admin/
routes is denied by default unless you’re on VPN. Because of this I want to expose both the Phoenix dashboard under the /admin
scope with…
scope "/admin" do
import Phoenix.LiveDashboard.Router
pipe_through [:fetch_session, :protect_from_forgery]
live_dashboard "/dashboard", metrics: MyApplicationWeb.Telemetry
end
scope "/admin" do
pipe_through [:api]
forward "/graphiql", Absinthe.Plug.GraphiQL,
schema: MyApplicationWeb.Schema,
interface: :playground,
context: %{pubsub: MyApplicationWeb.Endpoint}
end
An issue I’m seeing with this is that I’m duplicating scopes here and don’t understand enough about the Phoenix Router to know if this the right way to expose two different endpoints that require different pipelines under the same /admin
scope. I’ve gone ahead and tested out keeping them under the same scope but ran into some funky behavior where depending on how I order things I’ll get broken behavior.
For example, this seems to work:
scope "/admin" do
pipe_through [:api]
forward "/graphiql", Absinthe.Plug.GraphiQL,
schema: MyApplicationWeb.Schema,
interface: :playground,
context: %{pubsub: MyApplicationWeb.Endpoint}
import Phoenix.LiveDashboard.Router
pipe_through [:fetch_session, :protect_from_forgery]
live_dashboard "/dashboard", metrics: MyApplicationWeb.Telemetry
end
Whereas this does not work:
scope "/admin" do
import Phoenix.LiveDashboard.Router
pipe_through [:fetch_session, :protect_from_forgery]
live_dashboard "/dashboard", metrics: MyApplicationWeb.Telemetry
pipe_through [:api]
forward "/graphiql", Absinthe.Plug.GraphiQL,
schema: MyApplicationWeb.Schema,
interface: :playground,
context: %{pubsub: MyApplicationWeb.Endpoint}
end
Without knowing much more about how this works “under the hood”, I’m really just guessing at which will cause fewer problems in the long run. Curious if people have dealt with this situation before and how you think about