diff options
Diffstat (limited to 'src/guff/server.cr')
-rw-r--r-- | src/guff/server.cr | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/guff/server.cr b/src/guff/server.cr index bc4494c..1d87db7 100644 --- a/src/guff/server.cr +++ b/src/guff/server.cr @@ -1,41 +1,30 @@ require "http/server" require "./config" require "./model" -require "./blog-handler" +require "./handlers" module Guff class Server - def self.run(model : Model, config : Config) - new(model, config).run + def self.run(model : Model) + new(model).run end - def initialize(@model : Model, @config : Config) + def initialize(@model : Model) # create server @server = HTTP::Server.new( - config["host"], - config["port"].to_i, - get_handlers(model, config) + @model.config["host"], + @model.config["port"].to_i, + get_handlers(@model) ) end def run - puts "listening on %s:%s" % %w{host port}.map { |k| @config[k] } + puts "listening on %s:%s" % %w{host port}.map { |k| @model.config[k] } @server.listen end - private def get_handlers( - model : Model, - config : Config - ) : Array(HTTP::Handler) - @handlers ||= [ - HTTP::ErrorHandler.new, - HTTP::LogHandler.new, - HTTP::DeflateHandler.new, - BlogHandler.new(model, config), - SlugHandler.new(model, config), - HTTP::StaticFileHandler.new(config["public"]), - NotFoundHandler.new(model, config), - ] + private def get_handlers(model : Model) : Array(HTTP::Handler) + @handlers ||= Handlers.get(model) end end end |