Cowboy 服务器在启动时退出且没有错误
Cowboy server exits on start without errors
我是运行一个简单的牛仔服务员。这是我的申请文件:
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 docs:
mix run
can be used to start the current application dependencies, the
application itself, and optionally run some code in its context. For
long running systems, this is typically done with the --no-halt
option:
mix run --no-halt
我是运行一个简单的牛仔服务员。这是我的申请文件:
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 docs:
mix run
can be used to start the current application dependencies, the application itself, and optionally run some code in its context. For long running systems, this is typically done with the--no-halt
option:mix run --no-halt