Hello, I am working on an app and I want to separate admin and user routes to different subdomains, I found an article how-to-serve-multiple-domains-in-a-single-phoenix-app It got me part of the way there, but for some reason I can’t get it working the same way for example in the article:
scope "/", MyAppWeb, host: "music." do
live "/", MusicLive
end
# partial host match - match subdomain `video.`, i.e., matches `video.myapp.com`
scope "/", MyAppWeb, host: "video." do
live "/", VideoLive
end
# partial host match - match subdomain `admin.`, i.e., matches `admin.myapp.com`
scope "/", MyAppWeb, host: "admin." do
live "/", AdminLive, :home
live "/settings", AdminSettingsLive # admin.myapp.com/settings
end
They used “/” in different subdomains, however when I tried to do the same thing, I get a compiler warning this clause cannot match because a previous clause at line 30 always matchesElixir
.
# Public routes (no authentication required)
scope "/", AvocatoxWeb do
pipe_through :browser
# Add other public routes here
live "/", Home
end
# Admin routes (authentication required)
scope "/", AvocatoxWeb, host: "admin." do
pipe_through [:browser, :admin]
live "/", Admin.Home
end
It works when I go to http://localhost:4000 and http://admin.localhost:4000, but I get the same home function which is the first one.
I mean instead of this markup in the admin.
def render(assigns) do
~H"""
<div>
<h1>Admin Home</h1>
</div>
"""
end
I get this
def render(assigns) do
~H"""
<div>
<h1>Home</h1>
</div>
"""
end
I am new to elixir and phoenix and I am enjoying them a lot! Hopefully this is just a gap in my understanding. Thanks for your help in Advance.