diff --git a/dev.exs b/dev.exs index 1ccd4e42..7b989460 100644 --- a/dev.exs +++ b/dev.exs @@ -456,6 +456,13 @@ defmodule DemoWeb.Router do use Phoenix.Router import Phoenix.LiveDashboard.Router + forward "/admin", DemoWeb.Router.Admin +end + +defmodule DemoWeb.Router.Admin do + use Phoenix.Router + import Phoenix.LiveDashboard.Router + pipeline :browser do plug :fetch_session plug :protect_from_forgery @@ -470,6 +477,8 @@ defmodule DemoWeb.Router do get "/hello/:name", DemoWeb.PageController, :hello live_dashboard("/dashboard", + live_socket_path: "/live", + path_prefix: "/admin", env_keys: ["USER", "ROOTDIR"], metrics: DemoWeb.Telemetry, metrics_history: {DemoWeb.History, :data, []}, @@ -518,7 +527,7 @@ defmodule DemoWeb.Endpoint do same_site: "Lax" ] - socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] + socket "/admin/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket plug Phoenix.LiveReloader diff --git a/lib/phoenix/live_dashboard/page_builder.ex b/lib/phoenix/live_dashboard/page_builder.ex index cd56395f..3d3e4a6b 100644 --- a/lib/phoenix/live_dashboard/page_builder.ex +++ b/lib/phoenix/live_dashboard/page_builder.ex @@ -96,7 +96,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do We currently support `card/1`, `fields_card/1`, `row/1`, `shared_usage_card/1`, and `usage_card/1`; - and the live components `live_layered_graph/1`, `live_nav_bar/1`, + and the live components `live_layered_graph/1`, `live_nav_bar/1`, and `live_table/1`. ## Helpers @@ -956,7 +956,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do def live_dashboard_path(socket, route, node, old_params, new_params) when is_atom(node) do if function_exported?(socket.router, :__live_dashboard_prefix__, 0) do new_params = for {key, val} <- new_params, key not in ~w(page node), do: {key, val} - prefix = socket.router.__live_dashboard_prefix__() + prefix = socket.router.__live_dashboard_prefix__() |> dbg() path = if node == node() and is_nil(old_params["node"]) do diff --git a/lib/phoenix/live_dashboard/router.ex b/lib/phoenix/live_dashboard/router.ex index af07e785..4af8355c 100644 --- a/lib/phoenix/live_dashboard/router.ex +++ b/lib/phoenix/live_dashboard/router.ex @@ -97,6 +97,8 @@ defmodule Phoenix.LiveDashboard.Router do opts end + route_path_prefix = Keyword.get(opts, :path_prefix, "") <> path + scope = quote bind_quoted: binding() do scope path, alias: false, as: false do @@ -126,7 +128,9 @@ defmodule Phoenix.LiveDashboard.Router do unless Module.get_attribute(__MODULE__, :live_dashboard_prefix) do @live_dashboard_prefix Phoenix.Router.scoped_path(__MODULE__, path) + @live_dashboard_path_prefix Phoenix.Router.scoped_path(__MODULE__, route_path_prefix) def __live_dashboard_prefix__, do: @live_dashboard_prefix + def __live_dashboard_path_prefix__, do: @live_dashboard_path_prefix end end else