Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix beacon.gen.site result with host #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@
# General application configuration
import Config

config :beacon_demo, BeaconDemoWeb.NewEndpoint,
url: [host: "localhost"],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: BeaconDemoWeb.ErrorHTML, json: BeaconDemoWeb.ErrorJSON],
layout: false
],
pubsub_server: BeaconDemo.PubSub,
live_view: [signing_salt: "MuPZryYe"]

config :beacon_demo, BeaconDemoWeb.ProxyEndpoint, adapter: Bandit.PhoenixAdapter, live_view: [signing_salt: "MuPZryYe"]

config :beacon_demo,
ecto_repos: [BeaconDemo.Repo]
ecto_repos: [BeaconDemo.Repo],
session_options: [
store: :cookie,
key: "_beacon_demo_key",
signing_salt: "MuPZryYe",
same_site: "Lax"
]

# Configures the endpoint
config :beacon_demo, BeaconDemoWeb.Endpoint,
Expand All @@ -19,7 +37,7 @@ config :beacon_demo, BeaconDemoWeb.Endpoint,
layout: false
],
pubsub_server: BeaconDemo.PubSub,
live_view: [signing_salt: "O67x1k5A"]
live_view: [signing_salt: "MuPZryYe"]

# Configures the mailer
#
Expand Down
21 changes: 19 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import Config

config :beacon_demo, BeaconDemoWeb.NewEndpoint,
http: [ip: {127, 0, 0, 1}, port: 4369],
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "0mw75TEQj1HVQmPpsJNstRL0f2bGF6yFStBGhHt42XqyteBKM4fbOlMd7JLm5die",
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
]

config :beacon_demo, BeaconDemoWeb.ProxyEndpoint,
http: [ip: {127, 0, 0, 1}, port: 4000],
check_origin: false,
debug_errors: true,
secret_key_base: "0mw75TEQj1HVQmPpsJNstRL0f2bGF6yFStBGhHt42XqyteBKM4fbOlMd7JLm5die"

# Configure your database
config :beacon_demo, BeaconDemo.Repo,
username: "postgres",
Expand All @@ -19,11 +36,11 @@ config :beacon_demo, BeaconDemo.Repo,
config :beacon_demo, BeaconDemoWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4000],
http: [ip: {127, 0, 0, 1}, port: 4100],
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "A0DSgxjGCYZ6fCIrBlg6L+qC/cdoFq5Rmomm53yacVmN95Wcpl57Gv0sTJjKjtIp",
secret_key_base: "0mw75TEQj1HVQmPpsJNstRL0f2bGF6yFStBGhHt42XqyteBKM4fbOlMd7JLm5die",
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
Expand Down
26 changes: 17 additions & 9 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Config

config :beacon, new_site: [site: :new_site, repo: BeaconDemo.Repo, endpoint: BeaconDemoWeb.NewEndpoint, router: BeaconDemoWeb.Router]

config :beacon, :demo,
site: :demo,
repo: BeaconDemo.Repo,
Expand Down Expand Up @@ -61,17 +63,23 @@ if config_env() == :prod do
port = String.to_integer(System.get_env("PORT") || "4000")

config :beacon_demo, BeaconDemoWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
url: [host: host, port: 8443, scheme: "https"],
http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: 4100],
secret_key_base: secret_key_base

config :beacon_demo, BeaconDemoWeb.ProxyEndpoint,
check_origin: [host, "new.site.com"],
url: [port: 443, scheme: "https"],
http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
secret_key_base: secret_key_base,
server: !!System.get_env("PHX_SERVER")

config :beacon_demo, BeaconDemoWeb.NewEndpoint,
url: [host: "new.site.com", port: 8641, scheme: "https"],
http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: 4369],
secret_key_base: secret_key_base,
server: !!System.get_env("PHX_SERVER")

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
Expand Down
6 changes: 4 additions & 2 deletions lib/beacon_demo/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ defmodule BeaconDemo.Application do
# Start Finch
{Finch, name: BeaconDemo.Finch},
# Start Beacon sites
{Beacon, [sites: [Application.fetch_env!(:beacon, :demo)]]},
{Beacon, [sites: [Application.fetch_env!(:beacon, :demo), Application.fetch_env!(:beacon, :new_site)]]},
# Start the Endpoint (http/https)
BeaconDemoWeb.Endpoint
BeaconDemoWeb.Endpoint,
BeaconDemoWeb.NewEndpoint,
BeaconDemoWeb.ProxyEndpoint
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
2 changes: 0 additions & 2 deletions lib/beacon_demo_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ defmodule BeaconDemoWeb.Endpoint do
same_site: "Lax"
]

socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]

# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
Expand Down
39 changes: 39 additions & 0 deletions lib/beacon_demo_web/new_endpoint.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule BeaconDemoWeb.NewEndpoint do
use Phoenix.Endpoint, otp_app: :beacon_demo

@session_options Application.compile_env!(:beacon_demo, :session_options)

# socket /live must be in the proxy endpoint

# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :beacon_demo,
gzip: false,
only: BeaconDemoWeb.static_paths()

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :beacon_demo
end

plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug BeaconDemoWeb.Router
end
6 changes: 6 additions & 0 deletions lib/beacon_demo_web/proxy_endpoint.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defmodule BeaconDemoWeb.ProxyEndpoint do
use Beacon.ProxyEndpoint,
otp_app: :beacon_demo,
session_options: Application.compile_env!(:beacon_demo, :session_options),
fallback: BeaconDemoWeb.Endpoint
end
5 changes: 5 additions & 0 deletions lib/beacon_demo_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ defmodule BeaconDemoWeb.Router do
plug Beacon.LiveAdmin.Plug
end

scope "/", host: ["localhost", "new.site.com"] do
pipe_through [:browser, :beacon]
beacon_site "/", site: :new_site
end

scope "/admin" do
pipe_through [:browser, :beacon_admin]
beacon_live_admin "/"
Expand Down