diff --git a/shard.yml b/shard.yml index 686768b..0aff9de 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: kemal -version: 0.5.0 +version: 0.6.0 author: - Serdar Dogruyol diff --git a/spec/config_spec.cr b/spec/config_spec.cr index d4332f9..f9a5f5b 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -17,12 +17,18 @@ describe "Config" do config.env.should eq "development" end - it "set environment to production" do + it "sets environment to production" do config = Kemal.config config.env = "production" config.env.should eq "production" end + it "sets host binding" do + config = Kemal.config + config.host_binding = "127.0.0.1" + config.host_binding.should eq "127.0.0.1" + end + it "adds a custom handler" do config = Kemal.config config.add_handler CustomTestHandler.new diff --git a/spec/logger_spec.cr b/spec/logger_spec.cr index 82e59d1..e450c97 100644 --- a/spec/logger_spec.cr +++ b/spec/logger_spec.cr @@ -18,7 +18,6 @@ describe "Logger" do logger = Kemal::Logger.new logger.handler.should be_a File end - it "writes to a file in production" do config = Kemal.config config.env = "production" diff --git a/src/kemal.cr b/src/kemal.cr index 4a6d6c8..9d2638e 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -10,6 +10,9 @@ at_exit do opts.on("-e ", "--environment ", "environment") do |env| Kemal.config.env = env end + opts.on("-b", "--bind", "host binding") do |host_binding| + Kemal.config.host_binding = host_binding + end end config = Kemal.config @@ -18,9 +21,9 @@ at_exit do config.add_handler Kemal::StaticFileHandler.new(config.public_folder) config.add_handler Kemal::Handler::INSTANCE - server = HTTP::Server.new("0.0.0.0", config.port, config.handlers) + server = HTTP::Server.new(config.host_binding.not_nil!.to_slice, config.port, config.handlers) server.ssl = config.ssl - logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://0.0.0.0:#{config.port}\n" + logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" Signal::INT.trap { logger.write "Kemal is going to take a rest!\n" diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 1da0e65..0e9afec 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -4,9 +4,10 @@ module Kemal class Config INSTANCE = Config.new HANDLERS = [] of HTTP::Handler - property ssl, port, env, public_folder + property host_binding, ssl, port, env, public_folder def initialize + @host_binding = "0.0.0.0" unless @host_binding @port = 3000 @env = "development" unless @env @public_folder = "./public"