Skip to content

Commit 41eeb1a

Browse files
authored
Clarify app env usage (#11627)
1 parent 6e1632d commit 41eeb1a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/elixir/lib/config.ex

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,27 @@ defmodule Config do
6262
import_config config
6363
end
6464
65-
The last step is to replace all `Mix.env()` calls by `config_env()`.
65+
The last step is to replace all `Mix.env()` calls in the config files with `config_env()`.
66+
67+
Keep in mind you must also avoid using `Mix.env()` inside your project files.
68+
To check the environment at _runtime_, you may add a configuration key:
69+
70+
# config.exs
71+
...
72+
config :my_app, env: config_env()
73+
74+
Then, in other scripts and modules, you may get the environment with
75+
`Application.fetch_env!/2`:
76+
77+
# router.exs
78+
...
79+
if Application.fetch_env!(:my_app, :env) == :prod do
80+
...
81+
end
82+
83+
The only files where you may acccess functions from the `Mix` module are
84+
the `mix.exs` file and inside custom Mix tasks, which always within the
85+
`Mix.Tasks` namespace.
6686
6787
## config/runtime.exs
6888

0 commit comments

Comments
 (0)