Added Frank::Config

This commit is contained in:
Juan Wajnerman 2014-07-30 19:17:53 -03:00
parent a1c8a1b6f1
commit 69ed2d4612
2 changed files with 34 additions and 9 deletions

View file

@ -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

23
src/frank/config.cr Normal file
View file

@ -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