leptus module
Table of Contents
leptus module
Leptus high-level API for working with listeners.
Types
Listener = http | https
Handlers = [{HostMatch, [{module(), any()}]}]
AppName = atom()
HandlersOrAppName = Handlers | AppName
Option = {nb_acceptors, non_neg_integer()}
| {ip, inet:ip_address()}
| {port, inet:port_number()}
| {cacertfile, file:name_all()}
| {certfile, file:name_all()}
| {keyfile, file:name_all()}
| {static_dir, Dir :: file:name() | {priv_dir, App :: atom(), Dir :: file:name()}}
Options = [Option]
Functions
start_listener/2
Starts leptus' dependencies and a listener of type Listener.
leptus:start_listener(Listener, HandlersOrAppName) -> {ok, pid()}
Note that if you use AppName, Leptus will try to read
AppName/priv/leptus.config file
which should contain
{handlers, Handlers}.
{options, Options}.
start_listener/3
Starts leptus' dependencies and a listener of type Listener.
leptus:start_listener(Listener, Handlers, Options) -> {ok, pid()}
upgrade/0
Upgrades running listeners.
leptus:upgrade() -> ok
Assume we have the listener http running and its handlers are A, B and C,
this function will gather routes of A, B and C, and update the Cowboy
dispatch list.
upgrade/1
Upgrades a list of running listeners.
leptus:upgrade([Listner]) -> ok
This works like upgrade/0 but requires a list of listeners.
upgrade/2
Upgrades a running listener.
leptus:upgrade(Listener, Handlers) -> ok | {error, not_found}
For example, let's say, we have the listener http running and its
handlers are A, B and C, but we want to append a new handler that is called
D, so what we should do is using this function to update the Cowboy
dispatch list.
%% e.g.
Handlers = [{'_', [{A, AState}, {B, BState}, {C, CState}, {D, DState}]}],
leptus:upgrade(http, Handlers)
stop_listener/1
Stops a listener.
leptus:stop_listener(Listener) -> ok | {error, not_found}
running_listener/0
Returns a list of running listeners.
leptus:running_listener() -> [Listener]
listener_uptime/1
Returns uptime of a running listener.
leptus:listener_uptime(Listener) -> {Days :: integer(), calendar:time()} |
{error, not_found}