Skip to content

Commit

Permalink
v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sdogruyol committed Jan 3, 2016
1 parent c21567f commit 7ad319c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: kemal
version: 0.5.0
version: 0.6.0

author:
- Serdar Dogruyol <[email protected]>
8 changes: 7 additions & 1 deletion spec/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/logger_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions src/kemal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/kemal/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7ad319c

Please sign in to comment.