From b904af654cc970ed0b2850a91530c157bda3a949 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 21 Jul 2021 01:00:43 -0400 Subject: [PATCH] fix: don't consider `www.` as part of the host --- lib/ash_phoenix/plug/subdomain_plug.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ash_phoenix/plug/subdomain_plug.ex b/lib/ash_phoenix/plug/subdomain_plug.ex index 1850cfb..7c3eaee 100644 --- a/lib/ash_phoenix/plug/subdomain_plug.ex +++ b/lib/ash_phoenix/plug/subdomain_plug.ex @@ -100,7 +100,16 @@ defmodule AshPhoenix.SubdomainPlug do if host in [root_host, "localhost", "127.0.0.1", "0.0.0.0"] do nil else - String.replace(host, ~r/.?#{root_host}/, "") + host + |> String.trim_leading("www.") + |> String.replace(~r/.?#{root_host}/, "") + |> case do + "" -> + nil + + subdomain -> + subdomain + end end end end