【发布时间】:2020-09-18 09:30:33
【问题描述】:
我正在运行一个简单的牛仔服务器。这是我的申请文件:
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 后,我看到了启动日志(“正在启动...”),但我的应用程序立即退出而不是监听连接。如何让它无限期地收听?
【问题讨论】: