With Elixir / Phoenix (0.10.0), how do I set the port based on the PORT environment variable in the release?

In config/test.exsI have the following lines:

config :youli, Youli.Endpoint,
  http: [port: System.get_env("PORT") || 4001

When I launched mix release, canceled the release and launched the application with PORT = 4242, it runs on port 4001. Grapping is a bit, I found that it is hardcoded in this way to releases/0.0.3/sys.config.

How can I launch my release using a set of ports from the environment?

+4
source share
2 answers

System.get_env("PORT")Use instead {:system, "PORT"}:

$ git diff
diff --git a/phoenix/config/test.exs b/phoenix/config/test.exs
index 10cea91..617f34c 100644
--- a/phoenix/config/test.exs
+++ b/phoenix/config/test.exs
@@ -1,7 +1,7 @@
 use Mix.Config

  config :youli, Youli.Endpoint,
  -  http: [port: System.get_env("PORT") || 4001]
  +  http: [port: {:system, "PORT"}]

The documentation for this is lib/phoenix/endpoint.exin source at Phoenix.

+10
source

You can use {:system, "PORT"}or System.get_env("PORT").

0

All Articles