REVIEW

INTRO

REVIEW is a regular Erlang application.

HEADER

Picture 1. HOW TO SET UP BOTH APP AND SUP IN ERLANG
-module(review). -behaviour(supervisor). -behaviour(application). -export([init/1, start/0, start/2, stop/1, main/1]). -compile(export_all).

OTP

Note that suring start you should specify mauth module. Dafault implementation performs client topic autosubscription.

Picture 2. Implements Erlang/OTP service API
init([]) -> {ok, {{one_for_one, 5, 10}, [spec()]}}. start() -> start(normal,[]). start(_,_) -> emqttd_access_control:register_mod(auth, n2o_auth, [[]], 9998), supervisor:start_link({local,review},review,[]). stop(_) -> ok.

MOCHIWEB

REVIEW application uses MOCHIWEB as static HTTP server and as WebSocket proxy to MQTT server.

Picture 3. MOCHIWEB setup
spec() -> Acceptors = application:get_env(?MODULE, acceptors, 4), Clients = application:get_env(?MODULE, max_clients, 512), Protocol = application:get_env(?MODULE, protocol, http), Port = application:get_env(?MODULE, port, 8000), Options = [{max_clients, Clients}, {acceptors, Acceptors}], Args = [{mochiweb, handle, [docroot()]}], mochiweb:child_spec(Protocol, Port, Options, Args). docroot() -> {file, Here} = code:is_loaded(?MODULE), Dir = filename:dirname(filename:dirname(Here)), Root = application:get_env(?MODULE, "statics_root", "priv/static"), filename:join([Dir, Root]).