diff --git a/lib/beacon/proxy_endpoint.ex b/lib/beacon/proxy_endpoint.ex index 933b5d41e..01cb3a654 100644 --- a/lib/beacon/proxy_endpoint.ex +++ b/lib/beacon/proxy_endpoint.ex @@ -1,24 +1,22 @@ defmodule Beacon.ProxyEndpoint do - @moduledoc """ - Proxy Endpoint to redirect requests to each site endpoint in a multiple domains setup. + @moduledoc false - TODO: beacon.deploy.add_domain fobar + # Proxy Endpoint to redirect requests to each site endpoint in a multiple domains setup. + # + # TODO: beacon.deploy.add_domain fobar + # + # TODO: use Beacon.ProxyEndpoint, otp_app: :my_app, endpoints: [MyAppWeb.EndpointSiteA, MyAppWeb.EndpointSiteB] - TODO: use Beacon.ProxyEndpoint, otp_app: :my_app, endpoints: [MyAppWeb.EndpointSiteA, MyAppWeb.EndpointSiteB] - - """ - - @doc """ - TODO: doc - """ defmacro __using__(opts) do quote location: :keep, generated: true do - otp_app = Keyword.get(unquote(opts), :otp_app) || raise Beacon.RuntimeError, "FIXME missing otp_app" + otp_app = Keyword.get(unquote(opts), :otp_app) || raise Beacon.RuntimeError, "missing required option :otp_app in Beacon.ProxyEndpoint" + + session_options = + Keyword.get(unquote(opts), :session_options) || raise Beacon.RuntimeError, "missing required option :session_options in Beacon.ProxyEndpoint" - session_options = Keyword.get(unquote(opts), :session_options) || raise Beacon.RuntimeError, "FIXME missing session_options" Module.put_attribute(__MODULE__, :session_options, session_options) - fallback = Keyword.get(unquote(opts), :fallback) || raise Beacon.RuntimeError, "FIXME missing fallback" + fallback = Keyword.get(unquote(opts), :fallback) || raise Beacon.RuntimeError, "missing required option :fallback in Beacon.ProxyEndpoint" Module.put_attribute(__MODULE__, :__beacon_proxy_fallback__, fallback) use Phoenix.Endpoint, otp_app: otp_app @@ -30,13 +28,9 @@ defmodule Beacon.ProxyEndpoint do plug :proxy def proxy(conn, opts) do - require Logger - %{host: host} = conn - Logger.debug("@session_options => #{inspect(@session_options)}") - Logger.debug("conn.host => #{host}") - + # TODO: cache endpoint resolver endpoint = Enum.reduce_while(Beacon.Registry.running_sites(), @__beacon_proxy_fallback__, fn site, default -> %{endpoint: endpoint} = Beacon.Config.fetch!(site) @@ -48,8 +42,6 @@ defmodule Beacon.ProxyEndpoint do end end) - Logger.debug("endpoint => #{inspect(endpoint)}") - endpoint.call(conn, endpoint.init(opts)) end end diff --git a/lib/mix/tasks/beacon.gen.proxy_endpoint.ex b/lib/mix/tasks/beacon.gen.proxy_endpoint.ex index c7325b7e0..7cb4e5349 100644 --- a/lib/mix/tasks/beacon.gen.proxy_endpoint.ex +++ b/lib/mix/tasks/beacon.gen.proxy_endpoint.ex @@ -1,4 +1,6 @@ defmodule Mix.Tasks.Beacon.Gen.ProxyEndpoint do + @moduledoc false + use Igniter.Mix.Task @example "mix beacon.gen.proxy_endpoint"