Get current environment name

前端 未结 4 1608
野性不改
野性不改 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 16:35

    An alternative to putting the Mix.env/0 into your applications configuration is to use a module attribute. This also works in production because module attributes are evaluate at compile time.

    defmodule MyModule do
      @env Mix.env()
    
      def env, do: @env
    end
    

    If you only need the environment in a specific place - for example when starting up the application supervisor - this tends to be the easier solution.

提交回复
热议问题