Module: Quicsilver::RackHandler

Defined in:
lib/rackup/handler/quicsilver.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  Host: "0.0.0.0",
  Port: 4433,
}

Class Method Summary collapse

Class Method Details

.run(app, **options) {|server| ... } ⇒ Object

Yields:

  • (server)


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
45
46
47
48
49
50
# File 'lib/rackup/handler/quicsilver.rb', line 13

def self.run(app, **options)
  normalized_options = {
    host: options[:Host] || options[:host] || DEFAULT_OPTIONS[:Host],
    port: (options[:Port] || options[:port] || DEFAULT_OPTIONS[:Port]).to_i,
  }

  cert_file = options[:cert_file]
  key_file = options[:key_file]

  if cert_file.nil? && key_file.nil?
    env = options[:environment] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'

    if env == 'production'
      raise ArgumentError, "cert_file and key_file are required in production"
    else
      require 'localhost/authority'
      authority = Localhost::Authority.fetch
      cert_file = authority.certificate_path
      key_file = authority.key_path
      Quicsilver.logger.info("Using auto-generated certificates for localhost")
      Quicsilver.logger.info("  Cert: #{cert_file}")
      Quicsilver.logger.info("  Key: #{key_file}")
    end
  end

  config = ::Quicsilver::Transport::Configuration.new(cert_file, key_file)

  server = ::Quicsilver::Server.new(
    normalized_options[:port],
    address: normalized_options[:host],
    app: app,
    server_configuration: config
  )

  yield server if block_given?

  server.start
end

.valid_optionsObject



52
53
54
55
56
57
58
59
# File 'lib/rackup/handler/quicsilver.rb', line 52

def self.valid_options
  {
    "Host=HOST" => "Hostname to listen on (default: 0.0.0.0)",
    "Port=PORT" => "Port to listen on (default: 4433)",
    "cert_file=PATH" => "Path to TLS certificate file (required)",
    "key_file=PATH" => "Path to TLS key file (required)"
  }
end