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:
24
lib/berrypod_web/live_sandbox_hook.ex
Normal file
24
lib/berrypod_web/live_sandbox_hook.ex
Normal 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
|
||||
Reference in New Issue
Block a user