plugins.mk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # See LICENSE for licensing information.
  2. # Plain HTTP handlers.
  3. define tpl_cowboy.http
  4. -module($(n)).
  5. -behavior(cowboy_handler).
  6. -export([init/2]).
  7. init(Req, State) ->
  8. {ok, Req, State}.
  9. endef
  10. # Loop handlers.
  11. define tpl_cowboy.loop
  12. -module($(n)).
  13. -behavior(cowboy_loop).
  14. -export([init/2]).
  15. -export([info/3]).
  16. init(Req, State) ->
  17. {cowboy_loop, Req, State, hibernate}.
  18. info(_Info, Req, State) ->
  19. {ok, Req, State, hibernate}.
  20. endef
  21. # REST handlers.
  22. define tpl_cowboy.rest
  23. -module($(n)).
  24. -behavior(cowboy_rest).
  25. -export([init/2]).
  26. -export([content_types_provided/2]).
  27. -export([to_html/2]).
  28. init(Req, State) ->
  29. {cowboy_rest, Req, State}.
  30. content_types_provided(Req, State) ->
  31. {[
  32. {{<<"text">>, <<"html">>, '*'}, to_html}
  33. ], Req, State}.
  34. to_html(Req, State) ->
  35. {<<"<html><body>This is REST!</body></html>">>, Req, State}.
  36. endef
  37. # Websocket handlers.
  38. define tpl_cowboy.ws
  39. -module($(n)).
  40. -behavior(cowboy_websocket).
  41. -export([init/2]).
  42. -export([websocket_init/1]).
  43. -export([websocket_handle/2]).
  44. -export([websocket_info/2]).
  45. init(Req, State) ->
  46. {cowboy_websocket, Req, State}.
  47. websocket_init(State) ->
  48. {ok, State}.
  49. websocket_handle({text, Data}, State) ->
  50. {reply, {text, Data}, State};
  51. websocket_handle({binary, Data}, State) ->
  52. {reply, {binary, Data}, State};
  53. websocket_handle(_Frame, State) ->
  54. {ok, State}.
  55. websocket_info(_Info, State) ->
  56. {ok, State}.
  57. endef