sample.erl 1.1 KB

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