UP | HOME

leptus_router

Module

leptus_router

This module is used for collecting routes, and sorting them.

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 that 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"}}
       ]}]

Author: Sina Samavati

Created: 2018-09-19