Packages

HTTP and WebSocket echo server as an OTP Application

Current section

Files

Jump to
echo_boy lib echo_boy.ex
Raw

lib/echo_boy.ex

defmodule EchoBoy do
use Application
def start(_type, _args) do
children = [
Plug.Cowboy.child_spec(
scheme: :http,
plug: EchoBoy.Router,
options: [
port: EchoBoy.Config.port(),
dispatch: dispatch()
]
)
]
opts = [strategy: :one_for_one, name: EchoBoy.Supervisor]
Supervisor.start_link(children, opts)
end
defp dispatch do
[
{
:_,
[
{"/ws", EchoBoy.WebSocket, []},
{:_, Plug.Adapters.Cowboy.Handler, {EchoBoy.Router, []}}
]
}
]
end
end