Skip to content
This repository
Browse code

Add application and listener startup

  • Loading branch information...
commit 043cca2cfd04eb68df24022de1d665eb6fa00b4b 1 parent 45cbd3e
Loïc Hoguin authored
25 rebar.config
... ... @@ -0,0 +1,25 @@
  1 +{cover_enabled, true}.
  2 +{deps, [
  3 + {cowboy, "0\.6\.0",
  4 + {git, "git://github.com/extend/cowboy.git", "0.6.0"}},
  5 + {bullet, "0\.2\.0",
  6 + {git, "git://github.com/extend/bullet.git", "0.2.0"}},
  7 + {sheriff, "0\.4\.0",
  8 + {git, "git://github.com/extend/sheriff.git", "0.4.0"}},
  9 + {erlydtl, ".*",
  10 + {git, "https://github.com/evanmiller/erlydtl.git", "master"}},
  11 + {jsx, "1\.3",
  12 + {git, "git://github.com/talentdeficit/jsx.git", "master"}},
  13 + {gproc, "0\.2\.12",
  14 + {git, "git://github.com/esl/gproc.git", "master"}},
  15 + {lager, "1\.0\.0",
  16 + {git, "https://github.com/basho/lager.git", "master"}}
  17 +]}.
  18 +{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
  19 +{erl_opts, [
  20 +%% bin_opt_info,
  21 +%% warn_missing_spec,
  22 + warnings_as_errors,
  23 + warn_export_all,
  24 + {parse_transform, lager_transform}
  25 +]}.
26 src/farwest.app.src
... ... @@ -0,0 +1,26 @@
  1 +%% Copyright (c) 2012, Loïc Hoguin <essen@ninenines.eu>
  2 +%%
  3 +%% Permission to use, copy, modify, and/or distribute this software for any
  4 +%% purpose with or without fee is hereby granted, provided that the above
  5 +%% copyright notice and this permission notice appear in all copies.
  6 +%%
  7 +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8 +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9 +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10 +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11 +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12 +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13 +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14 +
  15 +{application, farwest, [
  16 + {description, "REST-based web development environment."},
  17 + {vsn, "0.1.0"},
  18 + {modules, []},
  19 + {registered, [farwest_sup]},
  20 + {applications, [
  21 + kernel,
  22 + stdlib
  23 + ]},
  24 + {mod, {farwest_app, []}},
  25 + {env, []}
  26 +]}.
30 src/farwest.erl
... ... @@ -0,0 +1,30 @@
  1 +%% Copyright (c) 2012, Loïc Hoguin <essen@ninenines.eu>
  2 +%%
  3 +%% Permission to use, copy, modify, and/or distribute this software for any
  4 +%% purpose with or without fee is hereby granted, provided that the above
  5 +%% copyright notice and this permission notice appear in all copies.
  6 +%%
  7 +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8 +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9 +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10 +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11 +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12 +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13 +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14 +
  15 +-module(farwest).
  16 +
  17 +%% API.
  18 +-export([start/0]).
  19 +
  20 +%% API.
  21 +
  22 +%% @doc Start Farwest and all its dependencies.
  23 +-spec start() -> ok.
  24 +start() ->
  25 + ok = application:start(compiler),
  26 + ok = application:start(syntax_tools),
  27 + ok = application:start(lager),
  28 + ok = application:start(gproc),
  29 + ok = application:start(cowboy),
  30 + ok = application:start(farwest).
43 src/farwest_app.erl
... ... @@ -0,0 +1,43 @@
  1 +%% Copyright (c) 2012, Loïc Hoguin <essen@ninenines.eu>
  2 +%%
  3 +%% Permission to use, copy, modify, and/or distribute this software for any
  4 +%% purpose with or without fee is hereby granted, provided that the above
  5 +%% copyright notice and this permission notice appear in all copies.
  6 +%%
  7 +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8 +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9 +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10 +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11 +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12 +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13 +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14 +
  15 +%% @private
  16 +-module(farwest_app).
  17 +-behaviour(application).
  18 +
  19 +%% API.
  20 +-export([start/2]).
  21 +-export([stop/1]).
  22 +
  23 +%% API.
  24 +
  25 +%% The priv_dir environment setting is mandatory.
  26 +start(_, _) ->
  27 + PrivDir = case application:get_env(farwest, priv_dir) of
  28 + {ok, PD} -> PD
  29 + end,
  30 + {ok, Dispatch} = file:consult(PrivDir ++ "/dispatch.conf"),
  31 + Port = case application:get_env(farwest, port) of
  32 + {ok, P} -> P;
  33 + undefined -> 8080
  34 + end,
  35 + {ok, _} = cowboy:start_listener(farwest, 100,
  36 + cowboy_tcp_transport, [{port, Port}],
  37 + cowboy_http_protocol, [{dispatch, Dispatch}]
  38 + ),
  39 + lager:info("Farwest listening on port ~p~n", [Port]),
  40 + farwest_sup:start_link().
  41 +
  42 +stop(_) ->
  43 + ok.
34 src/farwest_sup.erl
... ... @@ -0,0 +1,34 @@
  1 +%% Copyright (c) 2012, Loïc Hoguin <essen@ninenines.eu>
  2 +%%
  3 +%% Permission to use, copy, modify, and/or distribute this software for any
  4 +%% purpose with or without fee is hereby granted, provided that the above
  5 +%% copyright notice and this permission notice appear in all copies.
  6 +%%
  7 +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8 +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9 +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10 +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11 +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12 +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13 +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14 +
  15 +%% @private
  16 +-module(farwest_sup).
  17 +-behaviour(supervisor).
  18 +
  19 +%% API.
  20 +-export([start_link/0]).
  21 +
  22 +%% supervisor.
  23 +-export([init/1]).
  24 +
  25 +%% API.
  26 +
  27 +start_link() ->
  28 + supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  29 +
  30 +%% supervisor.
  31 +
  32 +init([]) ->
  33 + Procs = [],
  34 + {ok, {{one_for_one, 10, 10}, Procs}}.

0 comments on commit 043cca2

Please sign in to comment.
Something went wrong with that request. Please try again.