Skip to content

Commit

Permalink
Forward http port at application startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Jan 24, 2023
1 parent c829491 commit 8ed3ce7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 10 additions & 0 deletions lib/archethic/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ defmodule Archethic.Application do

port = Keyword.fetch!(p2p_endpoint_conf, :port)
{:ok, port} = Networking.try_open_port(port, true)
try_open_port(Keyword.get(web_endpoint_conf, :http))
try_open_port(Keyword.get(web_endpoint_conf, :https))

http = Keyword.fetch!(web_endpoint_conf, :http)
http_port = Keyword.fetch!(http, :port)

Expand Down Expand Up @@ -99,6 +102,13 @@ defmodule Archethic.Application do
Supervisor.start_link(Utils.configurable_children(children), opts)
end

defp try_open_port(nil), do: :ok

defp try_open_port(conf) do
port = Keyword.get(conf, :port)
Networking.try_open_port(port, false)
end

def config_change(changed, _new, removed) do
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
Expand Down
14 changes: 0 additions & 14 deletions lib/archethic_web/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule ArchethicWeb.Supervisor do

use Supervisor

alias Archethic.Networking
alias Archethic.Utils

alias ArchethicCache.LRU
Expand All @@ -19,12 +18,6 @@ defmodule ArchethicWeb.Supervisor do
end

def init(_) do
# Try to open the HTTP port
endpoint_conf = Application.get_env(:archethic, ArchethicWeb.Endpoint)

try_open_port(Keyword.get(endpoint_conf, :http))
try_open_port(Keyword.get(endpoint_conf, :https))

children =
[
TransactionCache,
Expand All @@ -43,13 +36,6 @@ defmodule ArchethicWeb.Supervisor do
Supervisor.init(children, opts)
end

defp try_open_port(nil), do: :ok

defp try_open_port(conf) do
port = Keyword.get(conf, :port)
Networking.try_open_port(port, false)
end

defp add_faucet_rate_limit_child(children) do
faucet_config = Application.get_env(:archethic, ArchethicWeb.FaucetController, [])

Expand Down

0 comments on commit 8ed3ce7

Please sign in to comment.