daily-tracker

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

runtime.exs (4793B)


      1 import Config
      2 
      3 # Make Erlang's DNS resolver respect /etc/hosts
      4 :inet_db.set_lookup([:file, :dns])
      5 
      6 # config/runtime.exs is executed for all environments, including
      7 # during releases. It is executed after compilation and before the
      8 # system starts, so it is typically used to load production configuration
      9 # and secrets from environment variables or elsewhere. Do not define
     10 # any compile-time configuration in here, as it won't be applied.
     11 # The block below contains prod specific runtime configuration.
     12 
     13 # ## Using releases
     14 #
     15 # If you use `mix release`, you need to explicitly enable the server
     16 # by passing the PHX_SERVER=true when you start it:
     17 #
     18 #     PHX_SERVER=true bin/daily_tracker start
     19 #
     20 # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
     21 # script that automatically sets the env var above.
     22 if System.get_env("PHX_SERVER") do
     23   config :daily_tracker, DailyTrackerWeb.Endpoint, server: true
     24 end
     25 
     26 config :daily_tracker, DailyTrackerWeb.Endpoint,
     27   http: [port: String.to_integer(System.get_env("PORT", "4000"))]
     28 
     29 if config_env() == :prod do
     30   database_url =
     31     System.get_env("DATABASE_URL") ||
     32       raise """
     33       environment variable DATABASE_URL is missing.
     34       For example: ecto://USER:PASS@HOST/DATABASE
     35       """
     36 
     37   maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
     38 
     39   config :daily_tracker, DailyTracker.Repo,
     40     # ssl: true,
     41     url: database_url,
     42     pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
     43     # For machines with several cores, consider starting multiple pools of `pool_size`
     44     # pool_count: 4,
     45     socket_options: maybe_ipv6
     46 
     47   # The secret key base is used to sign/encrypt cookies and other secrets.
     48   # A default value is used in config/dev.exs and config/test.exs but you
     49   # want to use a different value for prod and you most likely don't want
     50   # to check this value into version control, so we use an environment
     51   # variable instead.
     52   secret_key_base =
     53     System.get_env("SECRET_KEY_BASE") ||
     54       raise """
     55       environment variable SECRET_KEY_BASE is missing.
     56       You can generate one by calling: mix phx.gen.secret
     57       """
     58 
     59   host = System.get_env("PHX_HOST") || "example.com"
     60 
     61   config :daily_tracker, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
     62 
     63   config :daily_tracker, DailyTrackerWeb.Endpoint,
     64     url: [host: host, port: 443, scheme: "https"],
     65     http: [
     66       # Enable IPv6 and bind on all interfaces.
     67       # Set it to  {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
     68       # See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
     69       # for details about using IPv6 vs IPv4 and loopback vs public addresses.
     70       ip: {0, 0, 0, 0, 0, 0, 0, 0}
     71     ],
     72     secret_key_base: secret_key_base
     73 
     74   # ## SSL Support
     75   #
     76   # To get SSL working, you will need to add the `https` key
     77   # to your endpoint configuration:
     78   #
     79   #     config :daily_tracker, DailyTrackerWeb.Endpoint,
     80   #       https: [
     81   #         ...,
     82   #         port: 443,
     83   #         cipher_suite: :strong,
     84   #         keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
     85   #         certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
     86   #       ]
     87   #
     88   # The `cipher_suite` is set to `:strong` to support only the
     89   # latest and more secure SSL ciphers. This means old browsers
     90   # and clients may not be supported. You can set it to
     91   # `:compatible` for wider support.
     92   #
     93   # `:keyfile` and `:certfile` expect an absolute path to the key
     94   # and cert in disk or a relative path inside priv, for example
     95   # "priv/ssl/server.key". For all supported SSL configuration
     96   # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
     97   #
     98   # We also recommend setting `force_ssl` in your config/prod.exs,
     99   # ensuring no data is ever sent via http, always redirecting to https:
    100   #
    101   #     config :daily_tracker, DailyTrackerWeb.Endpoint,
    102   #       force_ssl: [hsts: true]
    103   #
    104   # Check `Plug.SSL` for all available options in `force_ssl`.
    105 
    106   mail_host = System.get_env("MAIL_HOST", "mail.silasbrack.com")
    107 
    108   mail_config =
    109     if mail_host == "localhost" do
    110       # Local delivery on the same machine — no TLS or auth needed
    111       [
    112         adapter: Swoosh.Adapters.SMTP,
    113         relay: "localhost",
    114         port: 25,
    115         tls: :never,
    116         ssl: false,
    117         auth: :never
    118       ]
    119     else
    120       [
    121         adapter: Swoosh.Adapters.SMTP,
    122         relay: mail_host,
    123         port: 25,
    124         username: "silas@silasbrack.com",
    125         password: System.get_env("MAIL_PASSWORD") ||
    126           raise("environment variable MAIL_PASSWORD is missing."),
    127         tls: :always,
    128         ssl: false,
    129         tls_options: [cacerts: :public_key.cacerts_get()],
    130         auth: :always
    131       ]
    132     end
    133 
    134   config :daily_tracker, DailyTracker.Mailer, mail_config
    135 end