This commit is contained in:
sdogruyol 2016-01-03 16:04:11 +02:00
parent c21567fe17
commit 7ad319c70d
5 changed files with 15 additions and 6 deletions

View file

@ -1,5 +1,5 @@
name: kemal
version: 0.5.0
version: 0.6.0
author:
- Serdar Dogruyol <dogruyolserdar@gmail.com>

View file

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

View file

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

View file

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

View file

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