aboutsummaryrefslogtreecommitdiff
path: root/src/guff/server.cr
blob: 8df68fa22ce07370ca1cc36fe675c5583a574fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require "http/server"
require "./config"
require "./models"
require "./handlers"

module Guff
  class Server
    def self.run(models : Models)
      new(models).run
    end

    def initialize(@models : Models)
      # create server
      @server = HTTP::Server.new(
        @models.config["host"],
        @models.config["port"].to_i,
        get_handlers(@models)
      )
    end

    def run
      puts "listening on %s:%s" % %w{host port}.map { |k| @models.config[k] }
      @server.listen
    end

    private def get_handlers(models : Models) : Array(HTTP::Handler)
      @handlers ||= Handlers.get(models)
    end
  end
end