Run Plug.Cowboy as a supervised handler
masterTo ensure reliability, start Plug.Cowboy as a child process within an OTP supervision tree. In your application's start/2 function, include the Plug.Cowboy specification in your list of children.
Common configuration keys for the child specification include:
scheme: The protocol to use (e.g.,:http).plug: The module implementing your Plug pipeline.port: The port number to listen on.
defmodule MyApp do
@moduledoc false
use Application
def start(_type, _args) do
children = [
{Plug.Cowboy, scheme: :http, plug: MyApp, port: 4040}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end