diff --git a/src/frank.cr b/src/frank.cr index 4efdd95..bf17a27 100644 --- a/src/frank.cr +++ b/src/frank.cr @@ -2,21 +2,23 @@ require "option_parser" require "./frank/*" $frank_handler = Frank::Handler.new -port = 3000 - -OptionParser.parse! do |opts| - opts.on("-p ", "--port ", "port") do |opt_port| - port = opt_port.to_i - end -end at_exit do + OptionParser.parse! do |opts| + opts.on("-p ", "--port ", "port") do |opt_port| + Frank.config.port = opt_port.to_i + end + end + + config = Frank.config handlers = [] of HTTP::Handler handlers << HTTP::LogHandler.new handlers << HTTP::StaticFileHandler.new("./public") handlers << $frank_handler - server = HTTP::Server.new(port, handlers) + server = HTTP::Server.new(config.port, handlers) - puts "Listening on http://0.0.0.0:#{port}" + server.ssl = config.ssl + + puts "Listening on #{config.scheme}://0.0.0.0:#{config.port}" server.listen end diff --git a/src/frank/config.cr b/src/frank/config.cr new file mode 100644 index 0000000..e1711cc --- /dev/null +++ b/src/frank/config.cr @@ -0,0 +1,23 @@ +module Frank + class Config + INSTANCE = Config.new + property ssl + property port + + def initialize + @port = 3000 + end + + def scheme + ssl ? "https" : "http" + end + end + + def self.config + yield Config::INSTANCE + end + + def self.config + Config::INSTANCE + end +end