websocket_app.erl 625 B

12345678910111213141516171819202122232425262728
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. %% @private
  3. -module(websocket_app).
  4. -behaviour(application).
  5. %% API.
  6. -export([start/2]).
  7. -export([stop/1]).
  8. %% API.
  9. start(_Type, _Args) ->
  10. Dispatch = cowboy_router:compile([
  11. {'_', [
  12. {"/", toppage_handler, []},
  13. {"/websocket", ws_handler, []},
  14. {"/static/[...]", cowboy_static, [
  15. {directory, {priv_dir, websocket, [<<"static">>]}},
  16. {mimetypes, {fun mimetypes:path_to_mimes/2, default}}
  17. ]}
  18. ]}
  19. ]),
  20. {ok, _} = cowboy:start_http(http, 100, [{port, 8080}],
  21. [{env, [{dispatch, Dispatch}]}]),
  22. websocket_sup:start_link().
  23. stop(_State) ->
  24. ok.