ex_trainer/config/runtime.exs
Joao P Dubas 58c010f486
All checks were successful
continuous-integration/drone/pr Build is passing
fix: get env from multiple sources
Rename function and return the first non nil value.
2024-09-25 10:44:57 +00:00

50 lines
1.4 KiB
Elixir

import Config
# [warn] Conditional IPv6 support missing from runtime configuration.
#
# Add the following to your config/runtime.exs:
#
# maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
#
# config :wabanex, Wabanex.Repo,
# ...,
# socket_options: maybe_ipv6
#
# [warn] Conditional server startup is missing from runtime configuration.
#
# Add the following to the top of your config/runtime.exs:
#
# if System.get_env("PHX_SERVER") do
# config :wabanex, WabanexWeb.Endpoint, server: true
# end
#
# [warn] Environment based URL export is missing from runtime configuration.
#
# Add the following to your config/runtime.exs:
#
# host = System.get_env("PHX_HOST") || "example.com"
#
# config :wabanex, WabanexWeb.Endpoint,
# ...,
# url: [host: host, port: 443]
config :wabanex, dns_cluster_query: System.get_env("DNS_CLUSTER_QUERY") || :ignore
multi_get_env = fn varnames, default ->
varnames
|> Enum.reduce(nil, fn
varname, nil ->
System.get_env(varname) || nil
_varname, value ->
value
end)
|> Kernel.||(default)
end
config :wabanex, Wabanex.Repo,
username: multi_get_env.(["DB_USER", "POSTGRES_USER"], "postgres"),
password: multi_get_env.(["DB_PASSWORD", "POSTGRES_PASS"], "postgres"),
hostname: multi_get_env.(["DB_HOST", "POSTGRES_HOST"], "localhost"),
port: System.get_env("DB_PORT") || "5432"