leptus_router module
Table of Contents
leptus_router module
This module is used for gathering routes and categorizing the dispatch the way the order of routes matters in Cowboy.
Types
Handlers = [{HostMatch, [{module(), State :: any()}]}]
Routes = cobwboy_router:routes()
Dispatch = cowboy_router:dispatch_rules()
Functions
paths/1
Gathers and makes a list of Cowboy routes.
paths(Handlers) -> Routes
sort_dispatch/1
Sorts dispatch the way order of routes matters in Cowboy.
sort_dispatch(Dispatch) -> Dispatch
static_file_routes/1
Makes routes to serve static files using Cowboy static handler.
static_file_routes({HostMatch, Dir | {priv_dir, App, Dir}}) -> Routes
NOTE: {priv_dir, App, Dir} will use the directory App/priv/Dir.
Assume we want to serve static files in /var/www which contains
index.html and static/css/style.css, we call this function like the
following:
static_file_routes({'_', "/var/www"})
and this will return:
[{'_', [
{"/", cowboy_static, {file, "/var/www/index.html"}},
{"/index.html", cowboy_static, {file, "/var/www/index.html"}},
{"/static/css/style.css", cowboy_static, {file, "/var/www/static/css/style.css"}}
]}]