REVIEW

INTRO

REVIEW is a regular Erlang application.

HEADER

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

OTP

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

Picture 2. Implements Erlang/OTP service API
start() -> start(normal,[]). start(_,_) -> supervisor:start_link({local,review},review,[]). stop(_) -> ok.

COWBOY

REVIEW WS application uses COWBOY as a static HTTP server and as a WebSocket server.

Picture 3. COWBOY setup
init([]) -> {ok, {{one_for_one, 5, 10}, [spec()]}}. spec() -> ranch:child_spec(http, 100, ranch_tcp, port(), cowboy_protocol, env()). env() -> [ { env, [ { dispatch, points() } ] } ]. static() -> { dir, "priv/static", mime() }. n2o() -> { dir, "deps/n2o/priv", mime() }. mime() -> [ { mimetypes, cow_mimetypes, all } ]. port() -> [ { port, application:get_env(n2o,port,8001) } ]. points() -> cowboy_router:compile([{'_', [ { "/n2o/[...]", n2o_static, n2o() }, { "/app/[...]", n2o_static, static() }, { "/ws/[...]", n2o_stream, [] } ]}]).

COWBOY2

COWBOY2 router is slick.

Picture 4. COWBOY2 setup
init([]) -> {ok, {{one_for_one, 5, 10}, []}}. points() -> cowboy_router:compile([{'_', [ {"/ws/[...]", n2o_cowboy2, []}, {"/n2o/[...]", cowboy_static, {priv_dir, n2o, []}}, {"/app/[...]", cowboy_static, {dir, "priv/static", []}} ]}]).