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

Forward http port at application startup #857

Merged
Merged
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
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