phoenix
phoenix copied to clipboard
Support list of hosts on router scope
trafficstars
I need to look into any implications of this, but I'd like to support router scopes where you can match on multiple hosts. For example, using LiveView's live routes today where you would like to route to different LiveViews based on the root host being accessed example.com vs username.example.com is not possible without branching to different routers in the endpoint. Supporting something like this would solve the issue:
# match www, no subdomain, and localhost
scope "/", MyAppWeb, host: ["www.", "example.com", "localhost"] do
live_session :default do
live "/", LandingLive, :new
end
end
# matched logged in subdomain user homepages
scope "/", MyAppWeb do
live_session :authenticated, on_mount: [{UserAuth, :ensure_authenticated}] do
live "/", HomeLive, :new
end
end