Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from archaelus/heroku

Heroku
  • Loading branch information...
commit 9b241d2d7a665693161ce565f6759d803971ed7c 2 parents 22f5e60 + d5e0768
@nisbus authored
View
1  .gitignore
@@ -7,3 +7,4 @@ deps
.#*
*.*~
rel/monterl_carlo_websocket/*
+erl_crash.dump
View
19 Makefile
@@ -0,0 +1,19 @@
+ERL ?= erl
+APP := monterl_carlo_websocket
+
+.PHONY: deps
+
+all: deps
+ @./rebar compile
+
+deps:
+ @./rebar get-deps
+
+clean:
+ @./rebar clean
+
+distclean: clean
+ @./rebar delete-deps
+
+docs:
+ @erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
View
1  Procfile
@@ -0,0 +1 @@
+web: erl -pa ebin -env ERL_LIBS deps -s monterl_carlo_websocket -monterl_carlo_websocket http_port $PORT -noshell -noinput -boot start_sasl
View
9 ebin/monterl_carlo_websocket.app
@@ -1,9 +0,0 @@
-{application,monterl_carlo_websocket,
- [{description,[]},
- {vsn,"1"},
- {registered,[]},
- {modules,[monterl_carlo_websocket,
- monterl_carlo_websocket_handler,
- monterl_carlo_websocket_sup]},
- {applications,[kernel,stdlib,inets,crypto,jsx,cowboy]},
- {mod,{monterl_carlo_websocket,[]}}]}.
View
8 src/monterl_carlo_websocket.app.src
@@ -3,8 +3,6 @@
{description, ""},
{vsn, "1"},
{registered, []},
- {modules,[monterl_carlo_websocket,
- monterl_carlo_websocket_handler]},
{applications, [
kernel,
stdlib,
@@ -13,5 +11,9 @@
jsx,
cowboy
]},
- {mod, { monterl_carlo_websocket, []}}
+ {mod, { monterl_carlo_websocket, []}},
+ {env,[]},
+ {start_phases,
+ [{listen,[]}
+ ]}
]}.
View
55 src/monterl_carlo_websocket.erl
@@ -1,11 +1,39 @@
-module(monterl_carlo_websocket).
-behaviour(application).
--export([start/2, stop/1]).
+-export([start/2, stop/1,start_phase/3]).
+-export([config/0, config/1, config/2,
+ start/0, a_start/2]).
+
+-define(APP,monterl_carlo_websocket).
+
+config(Key, Default) ->
+ case application:get_env(?APP, Key) of
+ undefined -> Default;
+ {ok, Val} -> Val
+ end.
+
+config(Key) ->
+ case application:get_env(?APP, Key) of
+ undefined -> erlang:error({missing_config, Key});
+ {ok, Val} -> Val
+ end.
+
+config() ->
+ application:get_all_env(?APP).
+start() ->
+ a_start(?APP, permanent).
+
start(_StartType, _StartArgs) ->
- %% {Host, list({Path, Handler, Opts})}
- %% Dispatch the requests (whatever the host is) to
- %% erws_handler, without any additional options.
+ monterl_carlo_websocket_sup:start_link().
+
+stop(_State) ->
+ ok.
+
+a_start(App, Type) ->
+ start_ok(App, Type, application:start(App, Type)).
+
+start_phase(listen,_Type,_Args) ->
Dispatch = [{'_', [
{[<<"index.html">>,'...'], cowboy_static,
[ {directory, {priv_dir, monterl_carlo_websocket,[]}},
@@ -16,11 +44,14 @@ start(_StartType, _StartArgs) ->
{file,<<"jquery.flot.js">>},
{mimetypes, [{<<".js">>, [<<"text/javascript">>]}]}]},
{'_', monterl_carlo_websocket_handler, []}
- ]}],
- %% Name, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
- %% Listen in 10100/tcp for http connections.
- cowboy:start_http(http, 100, [{port, 8080}],[{dispatch, Dispatch}]),
- monterl_carlo_websocket_sup:start_link().
-
-stop(_State) ->
- ok.
+ ]}],
+ cowboy:start_http(http, 100, [{port, config(http_port)}],[{dispatch, Dispatch}]),
+ ok.
+
+start_ok(_App, _Type, ok) -> ok;
+start_ok(_App, _Type, {error, {already_started, _App}}) -> ok;
+start_ok(App, Type, {error, {not_started, Dep}}) ->
+ ok = a_start(Dep, Type),
+ a_start(App, Type);
+start_ok(App, _Type, {error, Reason}) ->
+ erlang:error({app_start_failed, App, Reason}).

0 comments on commit 9b241d2

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