routes.erl 692 B

12345678910111213141516171819202122
  1. -module(routes).
  2. -author('Maxim Sokhatsky').
  3. -include_lib("n2o/include/wf.hrl").
  4. -export([init/2, finish/2]).
  5. finish(State, Ctx) -> {ok, State, Ctx}.
  6. init(State, Ctx) ->
  7. Path = wf:path(Ctx#context.req),
  8. wf:info(?MODULE,"Route: ~p~n",[Path]),
  9. {ok, State, Ctx#context{path=Path,module=route_prefix(Path)}}.
  10. route_prefix(<<"/ws/",P/binary>>) -> route(P);
  11. route_prefix(<<"/",P/binary>>) -> route(P);
  12. route_prefix(P) -> route(P).
  13. route(<<>>) -> index;
  14. route(<<"index">>) -> index;
  15. route(<<"login">>) -> login;
  16. route(<<"favicon.ico">>) -> static_file;
  17. route(<<"static/spa/spa.htm">>) -> login;
  18. route(<<"static/spa/index.htm">>) -> index;
  19. route(_) -> index.