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

@@ -275,21 +275,25 @@ defmodule BerrypodWeb.Router do
{BerrypodWeb.PageEditorHook, :mount_page_editor},
{BerrypodWeb.NewsletterHook, :mount_newsletter}
] do
live "/", Shop.Page, :home
live "/about", Shop.Page, :about
live "/delivery", Shop.Page, :delivery
live "/privacy", Shop.Page, :privacy
live "/terms", Shop.Page, :terms
live "/contact", Shop.Page, :contact
live "/collections/:slug", Shop.Page, :collection
live "/products/:id", Shop.Page, :product
live "/cart", Shop.Page, :cart
live "/search", Shop.Page, :search
live "/checkout/success", Shop.Page, :checkout_success
live "/orders", Shop.Page, :orders
live "/orders/:order_number", Shop.Page, :order_detail
# ┌─────────────────────────────────────────────────────────────────────┐
# │ Dynamic Shop Routes │
# │ │
# │ All shop pages are served by Shop.Page with runtime route resolution │
# │ via BerrypodWeb.R. This enables shop owners to customise URLs. │
# │ │
# │ Single-segment pages (/:slug): │
# │ /cart, /about, /contact, /search, /delivery, /privacy, /terms, │
# │ /orders, /checkout/success, plus custom CMS pages │
# │ │
# │ Two-segment pages (/:prefix/:id_or_slug): │
# │ /products/:id, /collections/:slug, /orders/:number │
# │ (prefixes are customisable, e.g. /p/:id, /shop/:slug) │
# │ │
# │ See: R.default_page_type/1, R.default_prefix_type/1, @page_modules │
# └─────────────────────────────────────────────────────────────────────┘
# Catch-all for custom CMS pages — must be last
live "/", Shop.Page, :home
live "/:prefix/:id_or_slug", Shop.Page, :dynamic_prefix
live "/:slug", Shop.Page, :custom_page
end