web_sup.erl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. -module(web_sup).
  2. -behaviour(supervisor).
  3. -export([start_link/0, init/1]).
  4. -compile(export_all).
  5. -include_lib ("n2o/include/wf.hrl").
  6. -include("users.hrl").
  7. -define(APP, web).
  8. start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  9. init([]) ->
  10. {ok, _} = cowboy:start_http(http, 100, [{port, wf:config(n2o,transition_port,8080)}],
  11. [{env, [{dispatch, dispatch_rules()}]}]),
  12. case file:read_file("/home/kakauser/cert/2014/startssl.ca") of
  13. {error,_} -> skip;
  14. {ok,_} ->
  15. {ok, _} = cowboy:start_https(https, 100, [
  16. {port, wf:config(n2o,port,8443)},
  17. {cacertfile, "/home/kakauser/cert/2014/startssl.ca"},
  18. {certfile, "/home/kakauser/cert/2014/kakaranet.com.crt"},
  19. {keyfile, "/home/kakauser/cert/2014/kakaranet.dec.key"} ],
  20. [{env, [{dispatch, dispatch_rules()}]}])
  21. end,
  22. {ok, {{one_for_one, 5, 10}, []}}.
  23. dispatch_rules() ->
  24. cowboy_router:compile(
  25. [{'_', [
  26. {"/static/[...]", cowboy_static,
  27. {priv_dir, ?APP, <<"static">>,[{mimetypes,cow_mimetypes,all}]}},
  28. {"/rest/:resource", rest_cowboy, []},
  29. {"/rest/:resource/:id", rest_cowboy, []},
  30. {"/ws/[...]", bullet_handler, [{handler, n2o_bullet}]},
  31. {'_', n2o_cowboy, []}
  32. ]}]).