nova_router
Nova router is in charge of all routing in Nova. When a nova application is started its routing-file is read and processed by the router. You should not use this module directly if you're not certain of what you are doing.
A basic routing file could look something like this;
#{prefix => "",
security => false,
routes => [
{"/", {hello_world_controller, index}},
{"/blog", {my_blog_controller, index}},
{404, {error_controller, not_found}}
],
statics => [
{"/assets/[...]", "assets"}
]
}.
Lets go through it in sections.
prefix - This tells us if the routes should have a common prefix (Eg "/v1" or similar)
security - If this is a tuple of type {Module, Function} Nova will try and call that function each time a page from the routes-section is visited. That function could return either true or false, telling nova if the user should be allowed to visit the page or not.
routes - Describes the routes inside this block. (An application can have several of these maps defined)
statics - Routes for all the static assets
Routing more in detail
There's three different ways of describing a route, depending on what kind of protocol (http, websocket) or what options you have.
{Route, {Module, Function}} - This is a regular route used for HTTP.Extend the introduction to how routing works.
Types
app_info/0
route/0
route_info/0
Functions
- Status = integer()
- Req = cowboy_req:req()
- RouteInfo = route_info()
- Route = route()
- App = atom()
- AppInfo = map()
We need this to work in a recursive manner.