【问题标题】:Mix release not working on Phoenix live view demo app混合版本不适用于 Phoenix 实时取景演示应用
【发布时间】:2021-04-26 01:42:45
【问题描述】:

背景

我在玩Phoenix LiveView,我已经用mix phx.new demo --live --no-ecto 设置了一个应用程序。

我的主要目标是创建此应用程序的版本,以便我可以根据需要对其进行调整,但我遇到了麻烦。

问题

为了为我的演示应用创建一个版本,我遵循了Deploying with releases 教程并更改了所有必要的文件。

将以下内容添加到我的mix.exs

  def project do
    [
      app: :demo,
      version: "0.1.0",
      elixir: "~> 1.7",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      releases: releases()
    ]
  end

  defp releases, do:
    [
      demo: [
        applications: [demo: :permanent]
      ]
    ]

并正确更改了运行时配置中列出的文件:

https://hexdocs.pm/phoenix/releases.html#runtime-configuration

但是,当我执行 _build/prod/rel/my_app/bin/demo start 时,什么也没有发生。如果我执行_build/prod/rel/my_app/bin/demo start_iex,我会得到以下输出:

$ _build/prod/rel/demo/bin/demo start_iex
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

*** ERROR: Shell process terminated! (^G to start new job) ***
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

Interactive Elixir (1.11.3) - press Ctrl+C to exit (type h() ENTER for help)
iex>

这让我相信有什么东西崩溃了。

当我访问 localhost:4000 时,它说服务器已关闭。

问题

我做错了什么?

【问题讨论】:

  • iex -S mix phx.server 运行显示任何错误?

标签: elixir phoenix-framework elixir-mix phoenix-live-view


【解决方案1】:

回答

问题出在我原来的配置文件config/config.exs中。

我有

# Configures the endpoint
config :demo, DemoWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "MY_SECRET_KEY",
  render_errors: [view: DemoWeb.ErrorView, accepts: ~w(html json), layout: false],
  pubsub_server: Demo.PubSub,
  live_view: [signing_salt: "yRZCwQIF"]

这里我漏掉了一行:

# Configures the endpoint
config :demo, DemoWeb.Endpoint,
  server: true

所以完整的配置应该是:

# Configures the endpoint
config :demo, DemoWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "MY_SECRET_KEY",
  render_errors: [view: DemoWeb.ErrorView, accepts: ~w(html json), layout: false],
  pubsub_server: Demo.PubSub,
  live_view: [signing_salt: "yRZCwQIF"],
  server: true

现在有了这个配置,服务器就可以工作了。

【讨论】:

  • 这在config/prod.exs 中有记录。我知道这并不容易找到。 :)
猜你喜欢
  • 2021-07-25
  • 2019-04-23
  • 1970-01-01
  • 2021-01-30
  • 1970-01-01
  • 2014-11-01
  • 2020-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多