From 52fff1f4ef9503457a6f4c18c25e6ca79cea15de Mon Sep 17 00:00:00 2001 From: Alexandre Moreira Xavier Date: Fri, 12 Jan 2024 18:31:24 -0300 Subject: [PATCH 1/3] Create doc/guide for multiple domains hosting with Beacon --- guides/deployment/multiple_domains_hosting.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 guides/deployment/multiple_domains_hosting.md diff --git a/guides/deployment/multiple_domains_hosting.md b/guides/deployment/multiple_domains_hosting.md new file mode 100644 index 000000000..8416d8ef6 --- /dev/null +++ b/guides/deployment/multiple_domains_hosting.md @@ -0,0 +1,59 @@ +# Multiple Domains/Tenants + +You can host multiple domains or subdomains with Phoenix by using the `:host` option of the scope function in your router: + +`:host` - a string or list of strings containing the host scope, or prefix host scope, ie "foo.bar.com", "foo." + +```elixir +# match admin. subdomain +scope "/", MyAppWeb, host: "admin." do + live "/", AdminLive, :new +end + +# match example.com, and "example2.com" +scope "/", MyAppWeb, host: ["example.com", "example2.com"] do + live "/", LandingLive, :new +end + +# match my-example.org +scope "/", MyAppWeb, host: "my-example.org" do + live "/", HomeLive, :new +end +``` + +## Multiple Domains/Tenants hosting with BeaconCMS + +So if you need to host multiple domains or subdomains in Beacon, you can use the same `:host` option: + +Here's another example, but now using Beacon: + +```elixir + scope "/", host: "demo.org" do + pipe_through :browser + + beacon_site "/demo", site: :demo + end + + scope "/", host: "blog.com" do + pipe_through :browser + + beacon_site "/blog", site: :blog + end + + scope "/admin" do + pipe_through :browser + beacon_live_admin "/" + end +``` + +You also need to pass the :check_origin option when configuring your +endpoint explicitly outlining which origins are allowed: + +`runtime.exs` +```elixir + check_origin: [ + "https://beacon-demo.com/", + "https://demo.org", + "https://blog.com" + ], +``` From c1413dac306c16b187245fec4b6bc96dda039c61 Mon Sep 17 00:00:00 2001 From: Alexandre Moreira Xavier Date: Fri, 12 Jan 2024 18:42:13 -0300 Subject: [PATCH 2/3] Update Multiple Domains Hosting guide --- guides/deployment/multiple_domains_hosting.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/guides/deployment/multiple_domains_hosting.md b/guides/deployment/multiple_domains_hosting.md index 8416d8ef6..0ecd91566 100644 --- a/guides/deployment/multiple_domains_hosting.md +++ b/guides/deployment/multiple_domains_hosting.md @@ -23,7 +23,7 @@ end ## Multiple Domains/Tenants hosting with BeaconCMS -So if you need to host multiple domains or subdomains in Beacon, you can use the same `:host` option: +So if you need to host multiple domains or subdomains with Beacon, you can use the same `:host` option: Here's another example, but now using Beacon: @@ -46,10 +46,11 @@ Here's another example, but now using Beacon: end ``` -You also need to pass the :check_origin option when configuring your +You also need to pass the `:check_origin` option when configuring your endpoint explicitly outlining which origins are allowed: -`runtime.exs` +Edit `config/runtime.exs` and edit the following config inside `config :my_app, MyAppWeb.Endpoint, ...`: + ```elixir check_origin: [ "https://beacon-demo.com/", From 95ebf6a064c1a555121f3a77920533b3a41b065f Mon Sep 17 00:00:00 2001 From: Alexandre Moreira Xavier Date: Fri, 26 Jan 2024 11:10:45 -0300 Subject: [PATCH 3/3] Improve multiple_domains_hosting doc --- guides/deployment/multiple_domains_hosting.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guides/deployment/multiple_domains_hosting.md b/guides/deployment/multiple_domains_hosting.md index 0ecd91566..63c7d07be 100644 --- a/guides/deployment/multiple_domains_hosting.md +++ b/guides/deployment/multiple_domains_hosting.md @@ -28,18 +28,21 @@ So if you need to host multiple domains or subdomains with Beacon, you can use t Here's another example, but now using Beacon: ```elixir + # serve the `:demo` site at demo.org/demo scope "/", host: "demo.org" do pipe_through :browser beacon_site "/demo", site: :demo end + # serve the `:blog` site at blog.com scope "/", host: "blog.com" do pipe_through :browser - beacon_site "/blog", site: :blog + beacon_site "/", site: :blog end + # serve the admin interface at the prefix /admin on the root domain scope "/admin" do pipe_through :browser beacon_live_admin "/"