Get current environment name

前端 未结 4 1609
野性不改
野性不改 2020-12-28 15:49

In Phoenix Framework, how can I get the current environment\'s name ?

I\'ve already tried reading env variables with System.get_env(\"MIX_ENV\")

4条回答
  •  一整个雨季
    2020-12-28 16:18

    Mix.env() doesn't work in production or other environments where you use compiled releases (built using Exrm / Distillery) or when Mix just isn't available.


    The solution is to specify it in your config/config.exs file:

    config :your_app, env: Mix.env()
    

    You can then get the environment atom in your application like this:

    Application.get_env(:your_app, :env)
    #=> :prod
    

提交回复
热议问题