diff --git a/lib/ash_admin/pages/page_live.ex b/lib/ash_admin/pages/page_live.ex index c3fc80f..c43ca7b 100644 --- a/lib/ash_admin/pages/page_live.ex +++ b/lib/ash_admin/pages/page_live.ex @@ -26,6 +26,18 @@ defmodule AshAdmin.PageLive do socket ) do otp_app = socket.endpoint.config(:otp_app) + + prefix = + case prefix do + "/" -> + session["request_path"] + + _ -> + request_path = session["request_path"] + [scope, _] = String.split(request_path, prefix) + scope <> prefix + end + socket = assign(socket, :prefix, prefix) actor_paused = diff --git a/lib/ash_admin/router.ex b/lib/ash_admin/router.ex index 861c019..532c15b 100644 --- a/lib/ash_admin/router.ex +++ b/lib/ash_admin/router.ex @@ -90,6 +90,8 @@ defmodule AshAdmin.Router do def __session__(conn, [session]), do: __session__(conn, session) def __session__(conn, session) do + session = Map.put(session, "request_path", conn.request_path) + Enum.reduce(@cookies_to_replicate, session, fn cookie, session -> case conn.req_cookies[cookie] do value when value in [nil, "", "null"] -> diff --git a/test/page_live_test.exs b/test/page_live_test.exs index aa384a4..4c92c10 100644 --- a/test/page_live_test.exs +++ b/test/page_live_test.exs @@ -1,7 +1,6 @@ defmodule AshAdmin.Test.PageLiveTest do use ExUnit.Case, async: false - import Plug.Conn import Phoenix.ConnTest import Phoenix.LiveViewTest @endpoint AshAdmin.Test.Endpoint @@ -11,10 +10,21 @@ defmodule AshAdmin.Test.PageLiveTest do end test "it renders the schema by default", %{conn: conn} do - {:ok, _view, html} = live(conn, "/Api/Post") + {:ok, _view, html} = live(conn, "/api/admin") + + assert html =~ "Attributes" + assert html =~ "body" + assert html =~ "String" + + {:ok, _view, html} = live(conn, "/api/admin/test") assert html =~ "Attributes" assert html =~ "body" assert html =~ "String" end + + test "it raises error when no route is found", %{conn: conn} do + assert_raise(Phoenix.Router.NoRouteError, fn -> live(conn, "/") end) + assert_raise(Phoenix.Router.NoRouteError, fn -> live(conn, "/Api/Post") end) + end end diff --git a/test/support/router.ex b/test/support/router.ex index 1a0a7c5..bc5ef5f 100644 --- a/test/support/router.ex +++ b/test/support/router.ex @@ -6,10 +6,10 @@ defmodule AshAdmin.Test.Router do plug(:fetch_query_params) end - scope "/" do + scope "/api" do pipe_through(:browser) import AshAdmin.Router - ash_admin("/") + ash_admin("/admin") end end