gpt4 book ai didi

elixir - 使用 Elixir/Phoenix (0.10.0),如何根据版本中的 PORT 环境变量设置端口?

转载 作者:行者123 更新时间:2023-12-04 22:45:30 26 4
gpt4 key购买 nike

config/test.exs ,我有以下几行:

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

当我跑 mix release ,解压发行版,并使用 PORT=4242 运行应用程序,它改为在端口 4001 上运行。仔细一想,我发现它在 releases/0.0.3/sys.config 中是这样硬编码的。 .

如何让我的版本使用环境中设置的端口运行?

最佳答案

而不是 System.get_env("PORT") , 使用 {: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"}]

相关文档在 lib/phoenix/endpoint.ex 中在 Phoenix 源。

关于elixir - 使用 Elixir/Phoenix (0.10.0),如何根据版本中的 PORT 环境变量设置端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29002709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com