Class: Identizer::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/identizer/server.rb

Overview

Runs the Rack App standalone over HTTPS (WEBrick). This is only needed for the standalone/CLI use case — when mounting Identizer inside an existing Rack/Rails app you use App directly and never touch this.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Identizer.configuration, app: nil) ⇒ Server

Returns a new instance of Server.



16
17
18
19
# File 'lib/identizer/server.rb', line 16

def initialize(config = Identizer.configuration, app: nil)
  @config = config
  @app = app || App.new(config)
end

Class Method Details

.start(config = Identizer.configuration, app: nil) ⇒ Object



12
13
14
# File 'lib/identizer/server.rb', line 12

def self.start(config = Identizer.configuration, app: nil)
  new(config, app: app).start
end

Instance Method Details

#mounted_serverObject

Build the WEBrick server with the Rack app mounted, without starting it. Exposed so tests can boot/stop it on an ephemeral port.



32
33
34
35
36
37
# File 'lib/identizer/server.rb', line 32

def mounted_server
  cert, key, @cert_path = TLS.resolve(@config)
  server = build_server(cert, key)
  server.mount_proc("/") { |request, response| dispatch(request, response) }
  server
end

#startObject



21
22
23
24
25
26
27
28
# File 'lib/identizer/server.rb', line 21

def start
  $stdout.sync = true
  server = mounted_server
  trap("INT") { server.shutdown }
  trap("TERM") { server.shutdown }
  print_banner(@cert_path)
  server.start
end