Module: Simple::Httpd::Server

Extended by:
Server
Included in:
Server
Defined in:
lib/simple/httpd/server.rb

Defined Under Namespace

Modules: NullLogger

Instance Method Summary collapse

Instance Method Details

#listen!(app, environment: "development", host: nil, port:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simple/httpd/server.rb', line 13

def listen!(app, environment: "development", host: nil, port:)
  expect! app != nil

  host ||= "127.0.0.1"
  URI("http://#{host}:#{port}") # validate host and port

  ::Simple::Httpd.logger.info "Starting httpd server on http://#{host}:#{port}/"

  app = ::Rack::CommonLogger.new(app)
  app = ::Rack::Lint.new(app) if environment != "production"

  # re/AccessLog: the AccessLog setting points WEBrick's access logging to the
  # NullLogger object.
  #
  # We do not set the environment. Rack is using this to load different
  # default middlewares (ShowException, Lint, CommonLogger) depending on
  # the environment setting (which should be either "development" or
  # "deployment").
  server_opts = {
    app: app,
    Host: host,
    Port: port,
    Logger: build_logger,
    AccessLog: [[NullLogger, ""]]
  }

  unless ::Simple::Httpd.env == "development"
    server_opts.update workers: 4, min_threads: 4
  end

  ::Rack::Server.start server_opts
end