From 740cb188a92ba33bc1d62257c0300eda505acdf3 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 30 Aug 2019 13:20:38 +0200 Subject: [PATCH] Check for KEMAL_ENV variable already in Config#initialize (#552) --- src/kemal/cli.cr | 25 +++++++++---------------- src/kemal/config.cr | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/kemal/cli.cr b/src/kemal/cli.cr index 656a4e6..b166708 100644 --- a/src/kemal/cli.cr +++ b/src/kemal/cli.cr @@ -8,7 +8,6 @@ module Kemal @key_file = "" @cert_file = "" @config = Kemal.config - read_env if args parse args end @@ -42,21 +41,15 @@ module Kemal private def configure_ssl {% if !flag?(:without_openssl) %} - if @ssl_enabled - abort "SSL Key Not Found" if !@key_file - abort "SSL Certificate Not Found" if !@cert_file - ssl = Kemal::SSL.new - ssl.key_file = @key_file.not_nil! - ssl.cert_file = @cert_file.not_nil! - Kemal.config.ssl = ssl.context - end - {% end %} - end - - private def read_env - if kemal_env = ENV["KEMAL_ENV"]? - @config.env = kemal_env - end + if @ssl_enabled + abort "SSL Key Not Found" if !@key_file + abort "SSL Certificate Not Found" if !@cert_file + ssl = Kemal::SSL.new + ssl.key_file = @key_file.not_nil! + ssl.cert_file = @cert_file.not_nil! + Kemal.config.ssl = ssl.context + end + {% end %} end end end diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 04bbdd7..2efcd66 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -29,7 +29,7 @@ module Kemal def initialize @host_binding = "0.0.0.0" @port = 3000 - @env = "development" + @env = ENV["KEMAL_ENV"]? || "development" @serve_static = {"dir_listing" => false, "gzip" => true} @public_folder = "./public" @logging = true