Add read config from yml

This commit is contained in:
Sdogruyol 2015-12-12 20:27:46 +02:00
parent 85a383b328
commit 58f9d8c590
2 changed files with 15 additions and 5 deletions

View File

@ -17,7 +17,7 @@ at_exit do
config = Kemal.config
logger = Kemal::Logger.new
config.add_handler logger
config.add_handler Kemal::StaticFileHandler.new("./public")
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
config.add_handler Kemal::Handler::INSTANCE
server = HTTP::Server.new(config.port, config.handlers)

View File

@ -1,16 +1,17 @@
require "yaml"
module Kemal
class Config
INSTANCE = Config.new
HANDLERS = [] of HTTP::Handler
property ssl
property port
property env
property workers
property ssl, port, env, workers, public_folder
def initialize
@port = 3000
@env = "development" unless @env
@workers = 1
@public_folder = "./public"
read_file
end
def scheme
@ -24,6 +25,15 @@ module Kemal
def add_handler(handler : HTTP::Handler)
HANDLERS << handler
end
def read_file
path = File.expand_path("config.yml", Dir.working_directory)
if File.exists?(path)
data = YAML.load(File.read(path)) as Hash
public_folder = File.expand_path("./#{data["public_folder"]}", Dir.working_directory)
@public_folder = public_folder
end
end
end
def self.config