Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrocp committed Dec 20, 2024
1 parent 2fe0bbd commit 438f49f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lib/beacon/proxy_endpoint.ex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -48,8 +42,6 @@ defmodule Beacon.ProxyEndpoint do
end
end)

Logger.debug("endpoint => #{inspect(endpoint)}")

endpoint.call(conn, endpoint.init(opts))
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/mix/tasks/beacon.gen.proxy_endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Mix.Tasks.Beacon.Gen.ProxyEndpoint do
@moduledoc false

use Igniter.Mix.Task

@example "mix beacon.gen.proxy_endpoint"
Expand Down

0 comments on commit 438f49f

Please sign in to comment.