2026-02-26 14:14:14 +00:00
|
|
|
defmodule BerrypodWeb.Plugs.BrokenUrlTracker do
|
|
|
|
|
@moduledoc """
|
|
|
|
|
Wraps the router to record 404s in the broken URLs table.
|
|
|
|
|
|
|
|
|
|
Works in dev mode too — Plug.Debugger intercepts exceptions before
|
|
|
|
|
error templates render, so we catch NoRouteError here, record it,
|
|
|
|
|
then re-raise so the normal error handling continues.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@behaviour Plug
|
|
|
|
|
|
|
|
|
|
def init(opts) do
|
|
|
|
|
router = Keyword.fetch!(opts, :router)
|
|
|
|
|
router_opts = router.init([])
|
|
|
|
|
{router, router_opts}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call(conn, {router, router_opts}) do
|
|
|
|
|
router.call(conn, router_opts)
|
|
|
|
|
rescue
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
e in [Phoenix.Router.NoRouteError, BerrypodWeb.NotFoundError] ->
|
2026-02-26 14:14:14 +00:00
|
|
|
unless static_path?(conn.request_path) do
|
2026-02-26 16:08:25 +00:00
|
|
|
prior_hits = Berrypod.Analytics.count_pageviews_for_path(conn.request_path)
|
|
|
|
|
Berrypod.Redirects.record_broken_url(conn.request_path, prior_hits)
|
|
|
|
|
|
|
|
|
|
if prior_hits > 0 do
|
|
|
|
|
Berrypod.Redirects.attempt_auto_resolve(conn.request_path)
|
|
|
|
|
end
|
2026-02-26 14:14:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
reraise e, __STACKTRACE__
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp static_path?(path) do
|
|
|
|
|
String.starts_with?(path, "/assets/") or
|
|
|
|
|
String.starts_with?(path, "/images/") or
|
2026-03-02 09:49:53 +00:00
|
|
|
String.starts_with?(path, "/image_cache/") or
|
2026-03-02 11:20:33 +00:00
|
|
|
String.starts_with?(path, "/mockups/") or
|
2026-02-26 14:14:14 +00:00
|
|
|
String.starts_with?(path, "/favicon")
|
|
|
|
|
end
|
|
|
|
|
end
|