elixir - 牛仔服务器在启动时退出而没有错误
问题描述
我正在运行一个简单的牛仔服务器。这是我的申请文件:
defmodule MyApp.Application do
@moduledoc "Application file"
use Application
def start(_type, _args) do
children = [
Plug.Cowboy.child_spec(
scheme: :http,
plug: MyApp.Web.Endpoint,
options: [port: 8000]
)
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
IO.puts("Starting...")
Supervisor.start_link(children, opts) |> IO.inspect
end
end
这是我的终点:
defmodule MyApp.Web.Endpoint do
@moduledoc """
This is the module responsible for processing incoming requests
"""
use Plug.Router
import Plug.Conn, only: [send_resp: 3]
plug(Plug.Logger)
plug(:match)
plug(:dispatch)
get "/ping" do
send_resp(conn, 200, "pong")
end
end
运行后mix run
,我看到启动日志(“正在启动...”),但我的应用程序立即退出而不是监听连接。我如何让它无限期地听?
解决方案
从混合运行文档:
mix run
可用于启动当前应用程序依赖项、应用程序本身,并可选择在其上下文中运行一些代码。对于长时间运行的系统,这通常通过以下--no-halt
选项完成:mix run --no-halt
推荐阅读
- java - 有错误 java.nio.file.FileSystemException 符号链接的级别太多或无法访问符号链接的属性
- c# - uwp 周年更新二进制格式化程序
- laravel - Laravel 6 与 Digital Ocean Managed Redis
- html - 如何使用 Javascript 对象中的变量值动态更改按钮的颜色?
- mongodb - 如何在 mongodb 中使用一个查询更新每个值
- ruby-on-rails - 在设置 Webpacker React 组件样式时,如何正确定义 backgroundImage 等 css 属性的图像 url?
- python - 如何从 android 获取请求到我的 django 视图?
- apache-kafka - 使用 kafka 将数据从 MySQL 导入 Postgres
- google-analytics - 如何使用标签管理器进行跨域,如果我更改我的代码站点,我会失去什么?
- c# - Unity 使用协程在 UI 中显示多张图片