routes.erl 621 B

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