add dynamic routes plug and simplify router

Dynamic prefix rewriting for custom URL prefixes:
- DynamicRoutes plug rewrites /p/123 to /products/123
- 301 redirects from canonical to custom prefix
- Router simplified to 3 catch-all routes
- LiveSandboxHook for test process ownership

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-04-01 00:35:49 +01:00
parent 6b90b394dd
commit ecf84b81d1
4 changed files with 151 additions and 16 deletions

View File

@@ -0,0 +1,24 @@
defmodule BerrypodWeb.LiveSandboxHook do
@moduledoc """
On-mount hook that allows LiveView processes to use the Ecto SQL sandbox.
Only active in test environment.
"""
import Phoenix.LiveView
import Phoenix.Component
def on_mount(:default, _params, _session, socket) do
socket =
assign_new(socket, :phoenix_ecto_sandbox, fn ->
if connected?(socket), do: get_connect_info(socket, :user_agent)
end)
metadata = socket.assigns.phoenix_ecto_sandbox
if metadata do
Phoenix.Ecto.SQL.Sandbox.allow(metadata, Ecto.Adapters.SQL.Sandbox)
end
{:cont, socket}
end
end