Add minimal configuration system

This commit is contained in:
Timothée Floure 2022-01-25 09:45:30 +01:00
parent 722bb69415
commit bea2f03f97
Signed by: tfloure
GPG Key ID: 4502C902C00A1E12
3 changed files with 12 additions and 16 deletions

6
config/config.exs Normal file
View File

@ -0,0 +1,6 @@
import Config
config :ha_handler,
http_port: 4000,
haproxy_socket: System.get_env("HAPROXY_SOCKET") || "/var/run/haproxy.sock"

View File

@ -1,18 +1,6 @@
defmodule HAHandler do defmodule HAHandler do
@moduledoc """ @moduledoc false
Documentation for `HAHandler`.
"""
@doc """ def http_port, do: Application.get_env(:ha_handler, :http_port)
Hello world. def haproxy_socket, do: Application.get_env(:ha_handler, :haproxy_socket)
## Examples
iex> HAHandler.hello()
:world
"""
def hello do
:world
end
end end

View File

@ -5,10 +5,12 @@ defmodule HAHandler.Application do
use Application use Application
import HAHandler
@impl true @impl true
def start(_type, _args) do def start(_type, _args) do
children = [ 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 # See https://hexdocs.pm/elixir/Supervisor.html