n2o_sample_app.erl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. -module(n2o_sample_app).
  2. -behaviour(application).
  3. -export([
  4. start/2,
  5. stop/1
  6. ]).
  7. -export([
  8. routes/0,
  9. update_routes/0
  10. ]).
  11. -define(MIME, [{mimetypes, cow_mimetypes, all}]).
  12. update_routes() ->
  13. Dispatch = routes(),
  14. cowboy:set_env(http, dispatch, Dispatch).
  15. %-define(STATIC, { dir, "apps/n2o_sample/priv", ?MIME }).
  16. -define(STATIC1, { dir, "apps/n2o_sample/priv/static", ?MIME }).
  17. -define(STATIC2, { dir, "apps/n2o_sample/priv/js", ?MIME }).
  18. -define(STATIC3, { dir, "apps/n2o_sample/priv/css", ?MIME }).
  19. %-define(STATIC_N4U, { dir, "deps/n4u/priv", ?MIME }).
  20. routes() ->
  21. cowboy_router:compile([{'_', [
  22. {"/static/[...]", n2o_static, ?STATIC1}, %% static without nginx by cowboy % todo : clean - mv to stc folder
  23. {"/js/[...]", n2o_static, ?STATIC2}, %% static without nginx by cowboy
  24. {"/css/[...]", n2o_static, ?STATIC3}, %% static without nginx by cowboy
  25. {"/img/[...]", n2o_static, ?STATIC1}, %% static without nginx by cowboy
  26. %{"/static/[...]", n2o_static, ?STATIC}, %% static without nginx by cowboy % todo : clean - mv to stc folder
  27. %{"/js/[...]", n2o_static, ?STATIC}, %% static without nginx by cowboy
  28. %{"/css/[...]", n2o_static, ?STATIC}, %% static without nginx by cowboy
  29. %{"/img/[...]", n2o_static, ?STATIC}, %% static without nginx by cowboy
  30. % {"/n4u/[...]", n2o_static, ?STATIC_N4U},%% static without nginx by cowboy
  31. {"/multipart/[...]", n2o_multipart, []},
  32. {"/rest/:resource", rest_cowboy, []},
  33. {"/rest/:resource/:id", rest_cowboy, []},
  34. {"/ws/[...]", n2o_stream, []},
  35. {'_', n2o_cowboy, []}
  36. ]}]).
  37. %start() -> start(normal,[]).
  38. start(_,_) ->
  39. %%[application:start(A) || A <- [asn1,kernel,stdlib,fs,ranch,compiler,syntax_tools,mnesia,crypto,inets,kvs,public_key,ssl,cowboy,n4u,n4u_sample,active,avz,epgsql,pooler,epgsql_pool,erlydtl,gproc,jsone,mad,nitro,oauth,rest,sh] ],
  40. %[application:start(A) || A <- [asn1,kernel,stdlib,fs,compiler,syntax_tools,mnesia,crypto,inets,kvs,public_key,ssl,ranch,cowboy,n4u,active,avz,epgsql,pooler,epgsql_pool,erlydtl,gproc,jsone,mad,nitro,oauth,rest,sh] ],% todo fix rest on erl24
  41. [application:start(A) || A <- [asn1,kernel,stdlib,fs,compiler,syntax_tools,mnesia,crypto,inets,kvs,public_key,ssl,ranch,cowboy,n4u,active,avz,epgsql,pooler,epgsql_pool,erlydtl,gproc,jsone,mad,nitro,oauth,sh] ],
  42. {ok, _} = application:ensure_all_started(ranch),
  43. {ok, _} = application:ensure_all_started(cowboy),
  44. n2o_sample_sup:start_link().
  45. stop(_) -> ok.