Check for KEMAL_ENV variable already in Config#initialize (#552)

This commit is contained in:
Sijawusz Pur Rahnama 2019-08-30 13:20:38 +02:00 committed by Serdar Dogruyol
parent 15022c25b8
commit 740cb188a9
2 changed files with 10 additions and 17 deletions

View file

@ -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

View file

@ -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