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

View File

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