Current section

54 Versions

Jump to

Compare versions

6 files changed
+40 additions
-36 deletions
  @@ -3,19 +3,18 @@
3 3 {<<"description">>,<<"Nova is a web application framework">>}.
4 4 {<<"files">>,
5 5 [<<"LICENSE">>,<<"README.md">>,<<"include/nova.hrl">>,
6 - <<"priv/nova.routes.erl">>,<<"priv/static/nova.png">>,<<"rebar.config">>,
7 - <<"rebar.lock">>,<<"src/controllers/nova_error_controller.erl">>,
8 - <<"src/nova.app.src">>,<<"src/nova.erl">>,<<"src/nova.hrl">>,
9 - <<"src/nova_app.erl">>,<<"src/nova_basic_handler.erl">>,
10 - <<"src/nova_erlydtl_inventory.erl">>,<<"src/nova_handler.erl">>,
11 - <<"src/nova_handlers.erl">>,<<"src/nova_internal_error.dtl">>,
12 - <<"src/nova_plugin.erl">>,<<"src/nova_plugin_handler.erl">>,
13 - <<"src/nova_router.erl">>,<<"src/nova_router.hrl">>,
14 - <<"src/nova_security_handler.erl">>,<<"src/nova_session.erl">>,
15 - <<"src/nova_session_ets.erl">>,<<"src/nova_stream_h.erl">>,
16 - <<"src/nova_sup.erl">>,<<"src/nova_watcher.erl">>,
17 - <<"src/nova_websocket.erl">>,<<"src/nova_ws_handler.erl">>,
18 - <<"src/plugins/nova_correlation_plugin.erl">>,
6 + <<"priv/static/nova.png">>,<<"rebar.config">>,<<"rebar.lock">>,
7 + <<"src/controllers/nova_error_controller.erl">>,<<"src/nova.app.src">>,
8 + <<"src/nova.erl">>,<<"src/nova.hrl">>,<<"src/nova_app.erl">>,
9 + <<"src/nova_basic_handler.erl">>,<<"src/nova_erlydtl_inventory.erl">>,
10 + <<"src/nova_handler.erl">>,<<"src/nova_handlers.erl">>,
11 + <<"src/nova_internal_error.dtl">>,<<"src/nova_plugin.erl">>,
12 + <<"src/nova_plugin_handler.erl">>,<<"src/nova_router.erl">>,
13 + <<"src/nova_router.hrl">>,<<"src/nova_security_handler.erl">>,
14 + <<"src/nova_session.erl">>,<<"src/nova_session_ets.erl">>,
15 + <<"src/nova_stream_h.erl">>,<<"src/nova_sup.erl">>,
16 + <<"src/nova_watcher.erl">>,<<"src/nova_websocket.erl">>,
17 + <<"src/nova_ws_handler.erl">>,<<"src/plugins/nova_correlation_plugin.erl">>,
19 18 <<"src/plugins/nova_cors_plugin.erl">>,
20 19 <<"src/plugins/nova_plugin_utilities.erl">>,
21 20 <<"src/plugins/nova_request_plugin.erl">>,<<"src/views/nova_error.dtl">>]}.
  @@ -51,4 +50,4 @@
51 50 [{<<"app">>,<<"uuid">>},
52 51 {<<"optional">>,false},
53 52 {<<"requirement">>,<<"~>2.0.0">>}]}]}.
54 - {<<"version">>,<<"0.8.6">>}.
53 + {<<"version">>,<<"0.9.0">>}.
  @@ -1,6 +0,0 @@
1 - #{
2 - routes => [
3 - {404, { nova_error_controller, not_found }, #{}},
4 - {500, { nova_error_controller, server_error }, #{}}
5 - ]
6 - }.
  @@ -1,6 +1,6 @@
1 1 {application,nova,
2 2 [{description,"Nova is a web application framework"},
3 - {vsn,"0.8.6"},
3 + {vsn,"0.9.0"},
4 4 {registered,[]},
5 5 {mod,{nova_app,[]}},
6 6 {included_applications,[]},
  @@ -8,6 +8,7 @@
8 8 -export([
9 9 get_main_app/0,
10 10 application_loaded/1,
11 + get_environment/0,
11 12 get_env/2,
12 13 set_env/2
13 14 ]).
  @@ -39,6 +40,8 @@ application_loaded(Application) ->
39 40 lists:any(fun({CompApp, _, _}) -> CompApp == Application end,
40 41 application:get_env(MainApp, nova_applications, [])).
41 42
43 + get_environment() ->
44 + application:get_env(nova, environment, dev).
42 45
43 46 %%--------------------------------------------------------------------
44 47 %% @doc
  @@ -15,13 +15,13 @@
15 15 %% API
16 16 -export([
17 17 compile/1,
18 - route_reader/1,
19 18 lookup_url/1,
20 19 lookup_url/2,
21 20 lookup_url/3,
22 21 render_status_page/2,
23 22 render_status_page/3,
24 - render_status_page/5
23 + render_status_page/5,
24 + routes/1
25 25 ]).
26 26
27 27 -include_lib("nova/include/nova.hrl").
  @@ -31,6 +31,10 @@
31 31 -type bindings() :: #{binary() := binary()}.
32 32 -export_type([bindings/0]).
33 33
34 + %% This module is also exposing callbacks for routers
35 + -callback routes(Env :: atom()) -> {ok, Routes :: any()}.
36 +
37 +
34 38 -spec compile(Apps :: [atom()]) -> host_tree().
35 39 compile(Apps) ->
36 40 UseStrict = application:get_env(nova, use_strict_routing, false),
  @@ -86,14 +90,6 @@ execute(Req = #{host := Host, path := Path, method := Method}, Env) ->
86 90 render_status_page(Host, 404, #{error => Error}, Req, Env)
87 91 end.
88 92
89 - -spec route_reader(App :: atom()) -> {ok, Terms :: [term()]} |
90 - {error, Reason :: atom() |
91 - {non_neg_integer(), atom(), atom()}}.
92 -
93 - route_reader(App) ->
94 - RoutePath = filename:join([code:priv_dir(App), erlang:atom_to_list(App) ++ ".routes.erl"]),
95 - file:consult(RoutePath).
96 -
97 93 lookup_url(Path) ->
98 94 lookup_url('_', Path).
99 95
  @@ -114,8 +110,10 @@ lookup_url(Host, Path, Method, Dispatch) ->
114 110 -spec compile(Apps :: [atom()], Dispatch :: host_tree(), Options :: map()) -> host_tree().
115 111 compile([], Dispatch, _Options) -> Dispatch;
116 112 compile([App|Tl], Dispatch, Options) ->
117 - {M, F} = application:get_env(nova, route_reader, {?MODULE, route_reader}),
118 - {ok, Routes} = M:F(App),
113 + %% Fetch the router-module for this application
114 + Router = erlang:list_to_atom(erlang:atom_to_list(App) ++ "_router"),
115 + Env = nova:get_environment(),
116 + Routes = Router:routes(Env),
119 117 Options1 = Options#{app => App},
120 118
121 119 {ok, Dispatch1, Options2} = compile_paths(Routes, Dispatch, Options1),
  @@ -391,6 +389,14 @@ persistent_get(Key, Env) ->
391 389 maps:get(Key, Env)
392 390 end.
393 391
392 + routes(_) ->
393 + [#{
394 + routes => [
395 + {404, { nova_error_controller, not_found }, #{}},
396 + {500, { nova_error_controller, server_error }, #{}}
397 + ]
398 + }].
399 +
394 400 -ifdef(TEST).
395 401 -compile(export_all). %% Export all functions for testing purpose
396 402 -include_lib("eunit/include/eunit.hrl").
Loading more files…