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>
25 lines
621 B
Elixir
25 lines
621 B
Elixir
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
|