Commit 7da8b0f1 authored by Frank Rousseau's avatar Frank Rousseau
Browse files

Set db and listening vars from environment

parent 7447547f
......@@ -12,9 +12,8 @@ use Mix.Config
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
config :gaja, Gaja.Endpoint,
http: [:inet6, port: {:system, "PORT"}],
url: [host: "localhost", port: System.get_env("PORT")],
cache_static_manifest: "priv/static/cache_manifest.json",
http: [:inet6, port: nil],
url: [host: "localhost", port: nil],
server: true,
root: ".",
version: Application.spec(:phoenix_distillery, :vsn)
......
......@@ -14,8 +14,9 @@ config :gaja, Gaja.Endpoint,
# Configure your database
config :gaja, Gaja.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("DATABASE_USER"),
password: System.get_env("DATABASE_PASS"),
database: System.get_env("DATABASE_NAME"),
hostname: System.get_env("DATABASE_HOST"),
username: "postgres",
password: "mysecretpassword",
database: "gaja",
hostname: "localhost",
port: "5432",
pool_size: 15
......@@ -39,4 +39,11 @@ defmodule Gaja.Endpoint do
signing_salt: "yRAUYsE8"
plug Gaja.Router
def init(_type, config) do
port = System.get_env("PORT") || 4000
host = System.get_env("HOST") || "localhost"
config = Keyword.put(config, :http, [:inet6, port: port])
config = Keyword.put(config, :url, [host: host, port: port])
{:ok, config}
end
end
defmodule Gaja.Repo do
use Ecto.Repo, otp_app: :gaja,
adapter: Ecto.Adapters.Postgres
def init(_, opts) do
{:ok, build_opts(opts)}
end
defp build_opts(opts) do
system_opts = [
database: System.get_env("DATABASE_NAME"),
hostname: System.get_env("DATABASE_HOST"),
password: System.get_env("DATABASE_PASS"),
username: System.get_env("DATABASE_USER"),
port: System.get_env("DATABASE_PORT")
]
system_opts
|> remove_empty_opts()
|> merge_opts(opts)
end
defp merge_opts(system_opts, opts) do
Keyword.merge(opts, system_opts)
end
defp remove_empty_opts(system_opts) do
Enum.reject(system_opts, fn {_k, value} -> is_nil(value) end)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment