mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add public_folder macro
This commit is contained in:
parent
b7ec6014aa
commit
aaa2ee1e31
3 changed files with 9 additions and 14 deletions
|
@ -28,4 +28,9 @@ describe "Config" do
|
||||||
config.add_handler CustomTestHandler.new
|
config.add_handler CustomTestHandler.new
|
||||||
config.handlers.size.should eq(1)
|
config.handlers.size.should eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "sets public folder" do
|
||||||
|
public_folder "/some/path/to/folder"
|
||||||
|
Kemal.config.public_folder.should eq("/some/path/to/folder")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,6 @@ module Kemal
|
||||||
@port = 3000
|
@port = 3000
|
||||||
@env = "development" unless @env
|
@env = "development" unless @env
|
||||||
@public_folder = "./public"
|
@public_folder = "./public"
|
||||||
read_file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def scheme
|
def scheme
|
||||||
|
@ -28,19 +27,6 @@ module Kemal
|
||||||
def add_ws_handler(handler : HTTP::WebSocketHandler)
|
def add_ws_handler(handler : HTTP::WebSocketHandler)
|
||||||
HANDLERS << handler
|
HANDLERS << handler
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def self.config
|
def self.config
|
||||||
|
|
|
@ -26,3 +26,7 @@ macro basic_auth(username, password)
|
||||||
auth_handler = Kemal::Middleware::HTTPBasicAuth.new("serdar", "123")
|
auth_handler = Kemal::Middleware::HTTPBasicAuth.new("serdar", "123")
|
||||||
Kemal.config.add_handler auth_handler
|
Kemal.config.add_handler auth_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro public_folder(path)
|
||||||
|
Kemal.config.public_folder = {{path}}
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue