๐Ÿ“ฆ juise / sherly

๐Ÿ“„ sherly_app.erl ยท 26 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26-module(sherly_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

%% ===================================================================
%% Application callbacks
%% ===================================================================

start(_StartType, _StartArgs) ->
    Dispatch = cowboy_router:compile([
        {'_', [
                {"/",               cowboy_static, {priv_file,  sherly, "index.html"}},
                {"/static/[...]",   cowboy_static, {priv_dir,   sherly, "static"}},
                {"/websocket",      sherly_ws, []}
            ]}
    ]),
    [{ok, IP}, {ok, Port}] = [application:get_env(sherly, Env) || Env <- [ip, port]],
    {ok, Pid} = cowboy:start_http(http, 100, [{ip, IP}, {port, Port}], [{env, [{dispatch, Dispatch}]}]),
    sherly_sup:start_link().

stop(_State) ->
    ok.