diff --git a/spec/config_spec.cr b/spec/config_spec.cr index d4332f9..cf02425 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -28,4 +28,9 @@ describe "Config" do config.add_handler CustomTestHandler.new config.handlers.size.should eq(1) end + + it "sets public folder" do + public_folder "/some/path/to/folder" + Kemal.config.public_folder.should eq("/some/path/to/folder") + end end diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 713e3ae..1da0e65 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -10,7 +10,6 @@ module Kemal @port = 3000 @env = "development" unless @env @public_folder = "./public" - read_file end def scheme @@ -28,19 +27,6 @@ module Kemal def add_ws_handler(handler : HTTP::WebSocketHandler) HANDLERS << handler end - - # Reads configuration from config.yml. Currently it only supports the public_folder - # option. - # config.yml - # public_folder = "root/to/folder" - def read_file - path = File.expand_path("config.yml", Dir.current) - if File.exists?(path) - data = YAML.load(File.read(path)) as Hash - public_folder = File.expand_path("./#{data["public_folder"]}", Dir.current) - @public_folder = public_folder - end - end end def self.config diff --git a/src/kemal/macros.cr b/src/kemal/macros.cr index a97b5bb..1ae818b 100644 --- a/src/kemal/macros.cr +++ b/src/kemal/macros.cr @@ -26,3 +26,7 @@ macro basic_auth(username, password) auth_handler = Kemal::Middleware::HTTPBasicAuth.new("serdar", "123") Kemal.config.add_handler auth_handler end + +macro public_folder(path) + Kemal.config.public_folder = {{path}} +end