diff --git a/config/config.exs b/config/config.exs new file mode 100644 index 0000000..9188d79 --- /dev/null +++ b/config/config.exs @@ -0,0 +1,6 @@ +import Config + +config :ha_handler, + http_port: 4000, + haproxy_socket: System.get_env("HAPROXY_SOCKET") || "/var/run/haproxy.sock" + diff --git a/lib/ha_handler.ex b/lib/ha_handler.ex index a57e7a1..a1d3b2e 100644 --- a/lib/ha_handler.ex +++ b/lib/ha_handler.ex @@ -1,18 +1,6 @@ defmodule HAHandler do - @moduledoc """ - Documentation for `HAHandler`. - """ + @moduledoc false - @doc """ - Hello world. - - ## Examples - - iex> HAHandler.hello() - :world - - """ - def hello do - :world - end + def http_port, do: Application.get_env(:ha_handler, :http_port) + def haproxy_socket, do: Application.get_env(:ha_handler, :haproxy_socket) end diff --git a/lib/ha_handler/application.ex b/lib/ha_handler/application.ex index dd4d493..27307b8 100644 --- a/lib/ha_handler/application.ex +++ b/lib/ha_handler/application.ex @@ -5,10 +5,12 @@ defmodule HAHandler.Application do use Application + import HAHandler + @impl true def start(_type, _args) do children = [ - {Plug.Cowboy, scheme: :http, plug: HAHandler.Web, options: [port: 4000]} + {Plug.Cowboy, scheme: :http, plug: HAHandler.Web, options: [port: http_port()]} ] # See https://hexdocs.pm/elixir/Supervisor.html