当你已经在 iex 中时如何启动 Phoenix 服务器?

How to start Phoenix server when you are already in iex?

我知道我们可以启动 iex -S mix phoenix.server。但是说我已经在 iex -S mix 中了。我该怎么做才能启动服务器?

谢谢。

很遗憾地告诉你,这不可能完成。

参考这个讨论:https://elixirforum.com/t/mix-task-run-deps-compile-dep-name-force-not-compiling/12114/4

我引用:

Mix is not intended to be called from iex or inside of your application. The primary interface is the CLI and because of this tasks are allowed to only run once.

只需以 iex -S mix phx.server 开始 运行ning,然后 iex 和您的应用程序将 运行 一起

这可能不是一个很好的方法,但我想你只是在开发中这样做。但是这样做的一种方法是设置 same config option mix phx.server 集然后重新启动您的端点(此示例停止它并让应用程序主管重新启动它)。

iex> Application.put_env(:phoenix, :serve_endpoints, true)
:ok
iex> GenServer.stop(MyAppWeb.Endpoint)
:ok
[info] Running MyAppWeb.Endpoint with cowboy 2.9.0 at 0.0.0.0:4000 (http)