Skip to content

Instantly share code, notes, and snippets.

@DavidAntaramian
Created July 6, 2018 16:44
Show Gist options
  • Save DavidAntaramian/74f61e57f18cde598bf36cdfce8758f6 to your computer and use it in GitHub Desktop.
Save DavidAntaramian/74f61e57f18cde598bf36cdfce8758f6 to your computer and use it in GitHub Desktop.
Using Ecto & Phoenix init/2 Callbacks
defmodule MyApp.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
# ... a bunch of plugs
def init(_, config) do
port = System.get_env("PORT")
http_config =
config
|> Keyword.get(:http, [])
|> Keyword.put_new(:port, port)
config = Keyword.put(:http, http_config)
{:ok, config}
end
end
defmodule MyApp.Repo do
use Ecto.Repo, opt_app: :my_app
# ... possibly other functionality
def init(_, config) do
url = System.get_env("DATABASE_URL")
config = Keyword.put_new(:url, url)
{:ok, config}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment