forked from inaka/cowboy_swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.erl
42 lines (35 loc) · 1.12 KB
/
example.erl
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-module(example).
-export([start/0]).
-export([start/2]).
-export([stop/0]).
-export([stop/1]).
-export([start_phase/3]).
%% application
%% @doc Starts the application
start() ->
application:ensure_all_started(example).
%% @doc Stops the application
stop() ->
application:stop(example).
%% behaviour
%% @private
start(_StartType, _StartArgs) ->
example_sup:start_link().
%% @private
stop(_State) ->
ok = cowboy:stop_listener(example_http).
-spec start_phase(atom(), application:start_type(), []) -> ok | {error, term()}.
start_phase(start_trails_http, _StartType, []) ->
{ok, Port} = application:get_env(example, http_port),
Trails = trails:trails([example_echo_handler,
example_description_handler,
cowboy_swagger_handler]),
trails:store(Trails),
Dispatch = trails:single_host_compile(Trails),
RanchOptions = [{port, Port}],
CowboyOptions = #{ env => #{dispatch => Dispatch}
, compress => true
, timeout => 12000
},
{ok, _} = cowboy:start_clear(example_http, RanchOptions, CowboyOptions),
ok.