From 80562b3bbf07148f4c7b793635cef146cc6f0ca4 Mon Sep 17 00:00:00 2001 From: Aleksei Magusev Date: Sun, 2 Nov 2014 12:05:51 +0100 Subject: [PATCH 1/2] Use `Application.get(fetch)_env/3(2)` functions --- lib/httparrot.ex | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/httparrot.ex b/lib/httparrot.ex index 24027ca..8b2c378 100644 --- a/lib/httparrot.ex +++ b/lib/httparrot.ex @@ -31,13 +31,12 @@ defmodule HTTParrot do {'/image', HTTParrot.ImageHandler, []}, {'/websocket', HTTParrot.WebsocketHandler, []} ] } ]) - {:ok, http_port} = :application.get_env(:httparrot, :http_port) - ssl = :application.get_env(:httparrot, :ssl, false) - {:ok, _} = :cowboy.start_http(:http, 100, [port: http_port], + {:ok, http_port} = Application.fetch_env(:httparrot, :http_port) + :cowboy.start_http(:http, 100, [port: http_port], [env: [dispatch: dispatch], onresponse: &prettify_json/4]) - if ssl do - {:ok, https_port} = :application.get_env(:httparrot, :https_port) + if Application.get_env(:httparrot, :ssl, false) do + {:ok, https_port} = Application.fetch_env(:httparrot, :https_port) priv_dir = :code.priv_dir(:httparrot) {:ok, _} = :cowboy.start_https(:https, 100, [port: https_port, cacertfile: priv_dir ++ '/ssl/server-ca.crt', From f49228fed267560eae3da48691ccc632c56476c2 Mon Sep 17 00:00:00 2001 From: Aleksei Magusev Date: Mon, 3 Nov 2014 00:26:04 +0100 Subject: [PATCH 2/2] No need in supervisor file --- lib/httparrot.ex | 14 +++++++++----- lib/httparrot/supervisor.ex | 12 ------------ 2 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 lib/httparrot/supervisor.ex diff --git a/lib/httparrot.ex b/lib/httparrot.ex index 8b2c378..8cce509 100644 --- a/lib/httparrot.ex +++ b/lib/httparrot.ex @@ -31,21 +31,25 @@ defmodule HTTParrot do {'/image', HTTParrot.ImageHandler, []}, {'/websocket', HTTParrot.WebsocketHandler, []} ] } ]) + {:ok, http_port} = Application.fetch_env(:httparrot, :http_port) - :cowboy.start_http(:http, 100, [port: http_port], - [env: [dispatch: dispatch], onresponse: &prettify_json/4]) + IO.puts "Starting HTTParrot on port #{http_port}" + {:ok, _} = :cowboy.start_http(:http, 100, + [port: http_port], + [env: [dispatch: dispatch], + onresponse: &prettify_json/4]) if Application.get_env(:httparrot, :ssl, false) do {:ok, https_port} = Application.fetch_env(:httparrot, :https_port) priv_dir = :code.priv_dir(:httparrot) + IO.puts "Starting HTTParrot on port #{https_port} (SSL)" {:ok, _} = :cowboy.start_https(:https, 100, [port: https_port, cacertfile: priv_dir ++ '/ssl/server-ca.crt', certfile: priv_dir ++ '/ssl/server.crt', keyfile: priv_dir ++ '/ssl/server.key'], [env: [dispatch: dispatch], onresponse: &prettify_json/4]) - IO.puts "Starting HTTParrot on port #{https_port} (SSL)" end - IO.puts "Starting HTTParrot on port #{http_port}" - HTTParrot.Supervisor.start_link + + Supervisor.start_link([], strategy: :one_for_one) end def stop(_State), do: :ok diff --git a/lib/httparrot/supervisor.ex b/lib/httparrot/supervisor.ex deleted file mode 100644 index 2a244cd..0000000 --- a/lib/httparrot/supervisor.ex +++ /dev/null @@ -1,12 +0,0 @@ -defmodule HTTParrot.Supervisor do - use Supervisor - - def start_link do - :supervisor.start_link({:local, __MODULE__}, __MODULE__, []) - end - - def init([]) do - children = [] - supervise children, strategy: :one_for_one - end -end