Created
July 6, 2018 16:44
-
-
Save DavidAntaramian/74f61e57f18cde598bf36cdfce8758f6 to your computer and use it in GitHub Desktop.
Using Ecto & Phoenix init/2 Callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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