websocket_app.erl 574 B

1234567891011121314151617181920212223242526
  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. {"/", cowboy_static, {priv_file, websocket, "index.html"}},
  13. {"/websocket", ws_handler, []},
  14. {"/static/[...]", cowboy_static, {priv_dir, websocket, "static"}}
  15. ]}
  16. ]),
  17. {ok, _} = cowboy:start_clear(http, 100, [{port, 8080}], #{
  18. env => #{dispatch => Dispatch}
  19. }),
  20. websocket_sup:start_link().
  21. stop(_State) ->
  22. ok.