-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create doc/guide for multiple domains hosting with Beacon (#393)
* Create doc/guide for multiple domains hosting with Beacon * Update Multiple Domains Hosting guide * Improve multiple_domains_hosting doc
- Loading branch information
1 parent
3981e3b
commit 9c2b8ef
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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 with Beacon, you can use the same `:host` option: | ||
|
||
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 "/", site: :blog | ||
end | ||
|
||
# serve the admin interface at the prefix /admin on the root domain | ||
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: | ||
|
||
Edit `config/runtime.exs` and edit the following config inside `config :my_app, MyAppWeb.Endpoint, ...`: | ||
|
||
```elixir | ||
check_origin: [ | ||
"https://beacon-demo.com/", | ||
"https://demo.org", | ||
"https://blog.com" | ||
], | ||
``` |