sample.erl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. -module(sample).
  2. -behaviour(supervisor).
  3. -behaviour(application).
  4. -export([init/1, start/2, stop/1, main/1]).
  5. -export([
  6. log_modules/0
  7. ]).
  8. main(A) -> mad_repl:sh(A).
  9. start(_,_) -> supervisor:start_link({local,sample},sample,[]).
  10. stop(_) -> ok.
  11. init([]) -> case cowboy:start_http(http,3,port(),env()) of
  12. {ok, _} -> ok;
  13. {error,_} -> halt(abort,[]) end, sup().
  14. sup() -> { ok, { { one_for_one, 5, 100 }, [] } }.
  15. env() -> [ { env, [ { dispatch, points() } ] } ].
  16. static() -> { dir, "apps/sample/priv/static", mime() }.
  17. n4u() -> { dir, "deps/n4u/priv", mime() }.
  18. mime() -> [ { mimetypes, cow_mimetypes, all } ].
  19. port() -> [ { port, wf:config(n4u,port,8001) } ].
  20. points() -> cowboy_router:compile([{'_', [
  21. { "/static/[...]", n2o_static, static() },
  22. { "/n4u/[...]", n2o_static, n4u() },
  23. { "/ws/[...]", n2o_stream, [] },
  24. { '_', n2o_cowboy, [] }]}]).
  25. log_modules() -> [n2o_client,n2o_nitrogen,n2o_stream,wf_convert].