toppage_handler.erl 562 B

1234567891011121314151617181920212223242526
  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,
  11. [{<<"content-type">>, <<"text/html">>}],
  12. Html, Req),
  13. {ok, Req2, State}.
  14. terminate(_Reason, _Req, _State) ->
  15. ok.
  16. get_html() ->
  17. {ok, Cwd} = file:get_cwd(),
  18. Filename =filename:join([Cwd, "priv", "html_ws_client.html"]),
  19. {ok, Binary} = file:read_file(Filename),
  20. Binary.