From 1dde6483202d4a960a44a0ccb5520a503044245b Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Fri, 24 Jan 2014 16:39:39 -0300 Subject: [PATCH] Check if ssl is enabled before starting [ci skip] --- lib/httparrot.ex | 18 +++++++++++------- mix.exs | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/httparrot.ex b/lib/httparrot.ex index f93a9b6..3892653 100644 --- a/lib/httparrot.ex +++ b/lib/httparrot.ex @@ -26,16 +26,20 @@ defmodule HTTParrot do {'/base64/:value', HTTParrot.Base64Handler, []} ] } ]) {:ok, http_port} = :application.get_env(:httparrot, :http_port) - {:ok, https_port} = :application.get_env(:httparrot, :https_port) + ssl = :application.get_env(:httparrot, :ssl, false) {:ok, _} = :cowboy.start_http(:http, 100, [port: http_port], [env: [dispatch: dispatch], onresponse: &prettify_json/4]) - priv_dir = :code.priv_dir(:httparrot) - {: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 #{http_port} and SSL on #{https_port}" + if ssl do + {:ok, https_port} = :application.get_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', + 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 end diff --git a/mix.exs b/mix.exs index 10545da..74e9d6d 100644 --- a/mix.exs +++ b/mix.exs @@ -15,7 +15,7 @@ defmodule Httparrot.Mixfile do :cowboy, :jsex ], mod: { HTTParrot, [] }, - env: [ http_port: 8080, https_port: 8433 ] ] + env: [ http_port: 8080, ssl: true, https_port: 8433 ] ] end defp deps(:dev) do