From d8930c8ecf45b0dd92b1f22c4f004c03aa2d877a Mon Sep 17 00:00:00 2001 From: APB9785 <74077809+APB9785@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:58:56 -0600 Subject: [PATCH] mix beacon.gen.site result with host --- config/config.exs | 22 +++++++++++++-- config/dev.exs | 21 +++++++++++++-- config/runtime.exs | 26 +++++++++++------- lib/beacon_demo/application.ex | 6 +++-- lib/beacon_demo_web/endpoint.ex | 2 -- lib/beacon_demo_web/new_endpoint.ex | 39 +++++++++++++++++++++++++++ lib/beacon_demo_web/proxy_endpoint.ex | 6 +++++ lib/beacon_demo_web/router.ex | 5 ++++ 8 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 lib/beacon_demo_web/new_endpoint.ex create mode 100644 lib/beacon_demo_web/proxy_endpoint.ex diff --git a/config/config.exs b/config/config.exs index 5b64953..b4fe583 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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, @@ -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 # diff --git a/config/dev.exs b/config/dev.exs index 0c33b89..7321702 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -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", @@ -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)]} diff --git a/config/runtime.exs b/config/runtime.exs index 964e2a2..c7ec16c 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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, @@ -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 diff --git a/lib/beacon_demo/application.ex b/lib/beacon_demo/application.ex index 45921fc..53355b9 100644 --- a/lib/beacon_demo/application.ex +++ b/lib/beacon_demo/application.ex @@ -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 diff --git a/lib/beacon_demo_web/endpoint.ex b/lib/beacon_demo_web/endpoint.ex index fec43ac..62b6e58 100644 --- a/lib/beacon_demo_web/endpoint.ex +++ b/lib/beacon_demo_web/endpoint.ex @@ -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 diff --git a/lib/beacon_demo_web/new_endpoint.ex b/lib/beacon_demo_web/new_endpoint.ex new file mode 100644 index 0000000..275750e --- /dev/null +++ b/lib/beacon_demo_web/new_endpoint.ex @@ -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 diff --git a/lib/beacon_demo_web/proxy_endpoint.ex b/lib/beacon_demo_web/proxy_endpoint.ex new file mode 100644 index 0000000..586db53 --- /dev/null +++ b/lib/beacon_demo_web/proxy_endpoint.ex @@ -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 diff --git a/lib/beacon_demo_web/router.ex b/lib/beacon_demo_web/router.ex index 35c35f4..e2e5363 100644 --- a/lib/beacon_demo_web/router.ex +++ b/lib/beacon_demo_web/router.ex @@ -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 "/"