File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,27 @@ defmodule Config do
62
62
import_config config
63
63
end
64
64
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.
66
86
67
87
## config/runtime.exs
68
88
You can’t perform that action at this time.
0 commit comments