toppage_handler.erl 521 B

123456789101112131415161718192021222324
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(toppage_handler).
  3. -export([init/3]).
  4. -export([handle/2]).
  5. -export([terminate/3]).
  6. init(_Transport, Req, []) ->
  7. {ok, Req, undefined}.
  8. handle(Req, State) ->
  9. Html = get_html(),
  10. {ok, Req2} = cowboy_req:reply(200, [], Html, Req),
  11. {ok, Req2, State}.
  12. terminate(_Reason, _Req, _State) ->
  13. ok.
  14. get_html() ->
  15. {ok, Cwd} = file:get_cwd(),
  16. Filename =filename:join([Cwd, "priv", "html_ws_client.html"]),
  17. {ok, Binary} = file:read_file(Filename),
  18. Binary.