Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Add non-catch-all version of dashboard route (#6327)

Uku Tahta08c881eb87c
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index 613929d534..4fac6d95cb 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -734,6 +734,7 @@ defmodule PlausibleWeb.Router do
put "/:domain/settings", SiteController, :update_settings
get "/:domain/export", StatsController, :csv_export
+ get "/:domain", StatsController, :stats
get "/:domain/*path", StatsController, :stats
end
end
diff --git a/test/plausible_web/components/billing/billing_test.exs b/test/plausible_web/components/billing/billing_test.exs
index 93ee24f79c..400af2c072 100644
--- a/test/plausible_web/components/billing/billing_test.exs
+++ b/test/plausible_web/components/billing/billing_test.exs
@@ -330,7 +330,7 @@ defmodule PlausibleWeb.Components.BillingTest do
)
assert element_exists?(html, "[data-test-id='total-pageviews-dashboard-link']")
- assert html =~ "/my-site.example.com/?period=custom"
+ assert html =~ "/my-site.example.com?period=custom"
end
test "renders no total link when no domain is provided" do
@@ -354,8 +354,8 @@ defmodule PlausibleWeb.Components.BillingTest do
html = render_monthly_pageview_usage(usage, 10_000)
- assert html =~ "/example.com/?period=custom"
- assert html =~ "/app.example.com/?period=custom"
+ assert html =~ "/example.com?period=custom"
+ assert html =~ "/app.example.com?period=custom"
end
test "dashboard links include the billing cycle date range" do
@@ -367,7 +367,7 @@ defmodule PlausibleWeb.Components.BillingTest do
)
assert html =~
- "/my-site.example.com/?period=custom&from=2024-01-01&to=2024-01-31"
+ "/my-site.example.com?period=custom&from=2024-01-01&to=2024-01-31"
end
end
diff --git a/test/plausible_web/controllers/invitation_controller_test.exs b/test/plausible_web/controllers/invitation_controller_test.exs
index ad3440f0fa..319afa46f4 100644
--- a/test/plausible_web/controllers/invitation_controller_test.exs
+++ b/test/plausible_web/controllers/invitation_controller_test.exs
@@ -20,7 +20,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
assert Phoenix.Flash.get(conn.assigns.flash, :success) ==
"You now have access to #{site.domain}"
- assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/"
+ assert redirected_to(conn) == Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)
refute Repo.exists?(from(i in Plausible.Teams.Invitation, where: i.email == ^user.email))
@@ -53,7 +53,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
invitation = invite_guest(site, user.email, role: :editor, inviter: owner)
c1 = post(conn, "/sites/invitations/#{invitation.invitation_id}/accept")
- assert redirected_to(c1) == "/#{URI.encode_www_form(site.domain)}/"
+ assert redirected_to(c1) == Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)
assert Phoenix.Flash.get(c1.assigns.flash, :success) ==
"You now have access to #{site.domain}"
@@ -78,7 +78,8 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
conn = post(conn, "/sites/invitations/#{transfer.transfer_id}/accept")
- assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/"
+ assert redirected_to(conn, 302) ==
+ Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)
assert Phoenix.Flash.get(conn.assigns.flash, :success) =~
"You now have access to"
@@ -140,7 +141,8 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
conn = post(conn, "/sites/invitations/#{transfer.transfer_id}/accept")
- assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/"
+ assert redirected_to(conn, 302) ==
+ Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)
assert Phoenix.Flash.get(conn.assigns.flash, :success) =~
"You now have access to"
@@ -208,7 +210,8 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
"/sites/invitations/#{transfer.transfer_id}/accept?skip_site_members_transfer=true"
)
- assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/"
+ assert redirected_to(conn, 302) ==
+ Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)
assert Phoenix.Flash.get(conn.assigns.flash, :success) =~
"You now have access to"
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index 7f227bdbce..e603dceb62 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -638,7 +638,7 @@ defmodule PlausibleWeb.SiteControllerTest do
}
})
- assert redirected_to(conn) == "/example.com/"
+ assert redirected_to(conn) == "/example.com"
end
end
diff --git a/test/plausible_web/live/customer_support/sites_test.exs b/test/plausible_web/live/customer_support/sites_test.exs
index 66e49f3843..e647710901 100644
--- a/test/plausible_web/live/customer_support/sites_test.exs
+++ b/test/plausible_web/live/customer_support/sites_test.exs
@@ -28,7 +28,10 @@ defmodule PlausibleWeb.Live.CustomerSupport.SitesTest do
~s|a[href$="#{URI.encode_www_form(site.domain)}/settings/general"]|
)
- assert element_exists?(html, ~s|a[href="/#{URI.encode_www_form(site.domain)}/"]|)
+ assert element_exists?(
+ html,
+ ~s|a[href="#{Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain)}"]|
+ )
end
test "404", %{conn: conn} do
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index fb273ca570..196979266e 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -178,7 +178,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
html = render(lv)
text = text(html)
- assert element_exists?(html, ~s|a[href="/primary.example.com%2Ftest/"]|)
+ assert element_exists?(html, ~s|a[href="/primary.example.com%2Ftest"]|)
assert element_exists?(html, ~s|a[href="/primary.example.com%2Ftest/settings/general"]|)
assert text =~ "primary.example.com/test"
diff --git a/test/plausible_web/live/verification_test.exs b/test/plausible_web/live/verification_test.exs
index 959af2645b..4580e932e9 100644
--- a/test/plausible_web/live/verification_test.exs
+++ b/test/plausible_web/live/verification_test.exs
@@ -195,7 +195,7 @@ defmodule PlausibleWeb.Live.VerificationTest do
build(:pageview)
])
- assert_redirect(lv, "/#{URI.encode_www_form(site.domain)}/")
+ assert_redirect(lv, Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain))
end
@tag :ce_build_only
@@ -207,7 +207,7 @@ defmodule PlausibleWeb.Live.VerificationTest do
populate_stats(site, [build(:pageview)])
- assert_redirect(lv, "/#{URI.encode_www_form(site.domain)}/")
+ assert_redirect(lv, Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain))
end
for {installation_type_param, expected_text, saved_installation_type} <- [