use Mix.Config

# For production, we configure the host to read the PORT
# from the system environment. Therefore, you will need
# to set PORT=80 before running your server.
#
# You should also configure the url host to something
# meaningful, we use this information when generating URLs.
#
# Finally, we also include the path to a manifest
# containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
config :cotoami, CotoamiWeb.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [
    scheme: System.get_env("COTOAMI_URL_SCHEME"),
    host: System.get_env("COTOAMI_URL_HOST"),
    port: (System.get_env("COTOAMI_URL_PORT") || "80") |> String.to_integer
  ],
  cache_static_manifest: "priv/static/cache_manifest.json",
  secret_key_base: System.get_env("SECRET_KEY_BASE")

# Do not print debug messages in production
config :logger, level: :info

# Configure your database
case System.get_env("DATABASE_URL") do
  nil ->
    config :cotoami, Cotoami.Repo,
      adapter: Ecto.Adapters.Postgres,
      username: System.get_env("COTOAMI_REPO_USER"),
      password: System.get_env("COTOAMI_REPO_PASSWORD"),
      database: System.get_env("COTOAMI_REPO_DATABASE"),
      hostname: System.get_env("COTOAMI_REPO_HOST"),
      pool_size: 5,
      timeout: 300_000
  url ->
    config :cotoami, Cotoami.Repo,
      adapter: Ecto.Adapters.Postgres,
      url: url,
      pool_size: 5,
      ssl: true,
      timeout: 300_000
end

