【发布时间】:2016-09-21 09:49:44
【问题描述】:
我对 Phoenix 端点配置中的 host: 参数的工作方式感到困惑。
我分别使用不同的 URL 部署到不同的 Heroku 应用程序(prod 和 staging)。我想将主机 URL 配置为动态的,来自环境变量,如下所示:
config :testapp, TestApp.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: {:system, "HOST"}, port: 443],
cache_static_manifest: "priv/static/manifest.json",
force_ssl: [rewrite_on: [:x_forwarded_proto]],
secret_key_base: System.get_env("SECRET_KEY_BASE")
但是,在部署之后,我的资产 URL 不再具有 phoenix.digest 设置的唯一哈希值,这会破坏交易。
有趣的是,当我对 URL 进行硬编码时:
config :testapp, TestApp.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "someapp-staging.herokuapp.com", port: 443],
cache_static_manifest: "priv/static/manifest.json",
force_ssl: [rewrite_on: [:x_forwarded_proto]],
secret_key_base: System.get_env("SECRET_KEY_BASE")
即使它与 Heroku 应用程序 url 不匹配,一切似乎仍然正常,并且资产 URL 是正确的。例如。我可以使用 URL foo.herokuapp.com 部署到应用程序,一切仍然有效。
以上配置来自prod.exs,我使用的是elixir和phoenix静态自定义buildpacks,配置如下:
# elixir_buildpack.config
# Elixir version
elixir_version=1.2.3
# Always rebuild from scratch on every deploy?
always_rebuild=true
# ENV variables
config_vars_to_export=(DATABASE_URL HOST)
和
# phoenix_static_buildpack.config
# We can set the version of Node to use for the app here
node_version=5.10.0
# We can set the version of NPM to use for the app here
npm_version=3.8.3
# ENV variables
config_vars_to_export=(DATABASE_URL HOST)
我可能会引入一个单独的staging.exs 配置文件并设置MIX_ENV=staging,但我想了解:
1) 为什么使用 {:system, "HOST"} 会破坏已消化的资产 URL
2) 为什么任何字符串在不同的应用程序和 URL 上都能正常工作
感谢任何帮助!
【问题讨论】:
标签: heroku elixir phoenix-framework