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

@@ -13,8 +13,8 @@ defmodule BerrypodWeb.Endpoint do
]
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]],
longpoll: [connect_info: [session: @session_options]]
websocket: [connect_info: [:user_agent, session: @session_options]],
longpoll: [connect_info: [:user_agent, session: @session_options]]
# In prod, image variants and mockups live on the persistent volume
# rather than inside the ephemeral release directory.
@@ -50,6 +50,11 @@ defmodule BerrypodWeb.Endpoint do
plug Tidewave, allow_remote_access: true
end
# Enable sandbox for LiveView tests (allows LV processes to share test DB connection)
if Application.compile_env(:berrypod, :env) == :test do
plug Phoenix.Ecto.SQL.Sandbox
end
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
@@ -76,5 +81,6 @@ defmodule BerrypodWeb.Endpoint do
plug Plug.Head
plug Plug.Session, @session_options
plug BerrypodWeb.Plugs.Redirects
plug BerrypodWeb.Plugs.DynamicRoutes
plug BerrypodWeb.Plugs.BrokenUrlTracker, router: BerrypodWeb.Router
end