elstat/lib/cowboy.ex

41 lines
849 B
Elixir
Raw Normal View History

2018-06-10 21:56:59 +00:00
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([
{:_, [
2018-06-11 21:36:16 +00:00
{"/", :cowboy_static, {:file, "static/index.html"}},
2018-06-11 20:42:40 +00:00
{"/hewwo", Elstat.Cowboy.DefaultHandler, []},
{"/api/current_status", Elstat.API.Status, []},
2018-06-10 21:56:59 +00:00
]}
])
end
end