defmodule Elstat.Cowboy.DefaultHandler do def init(req0, state) do # TODO: find a way to send a html file # instead of hewwo owo req = :cowboy_req.reply(200, %{"content-type" => "text/plain"}, "hewwo", req0 ) {:ok, req, state} end end defmodule Elstat.Cowboy do def start_link do dispatch_config = build_dispatch_config() port = Application.fetch_env!(:elstat, :port) {:ok, _} = :cowboy.start_clear( :elstat, [{:port, port}], %{env: %{dispatch: dispatch_config}} ) end def build_dispatch_config do :cowboy_router.compile([ {:_, [ {"/", Elstat.Cowboy.DefaultHandler, []}, {"/api", Elstat.Cowboy.APIHandler, []}, ]} ]) end end