class Middleman::PreviewServer

def setup_webrick(is_logging)

Returns:
  • (void) -
def setup_webrick(is_logging)
  http_opts = {
    Port: server_information.port,
    AccessLog: [],
    ServerName: server_information.server_name,
    BindAddress: server_information.bind_address.to_s,
    DoNotReverseLookup: true
  }
  if server_information.https?
    http_opts[:SSLEnable] = true
    if ssl_certificate || ssl_private_key
      raise 'You must provide both :ssl_certificate and :ssl_private_key' unless ssl_private_key && ssl_certificate
      http_opts[:SSLCertificate] = OpenSSL::X509::Certificate.new ::File.read ssl_certificate
      http_opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new ::File.read ssl_private_key
    else
      # use a generated self-signed cert
      http_opts[:SSLCertName] = [
        %w(CN localhost),
        %w(CN #{host})
      ].uniq
      cert, key = create_self_signed_cert(1024, [['CN', server_information.server_name]], server_information.site_addresses, 'Middleman Preview Server')
      http_opts[:SSLCertificate] = cert
      http_opts[:SSLPrivateKey] = key
    end
  end
  http_opts[:Logger] = if is_logging
    FilteredWebrickLog.new
  else
    ::WEBrick::Log.new(nil, 0)
  end
  begin
    ::WEBrick::HTTPServer.new(http_opts)
  rescue Errno::EADDRINUSE
    $stderr.puts %(== Port "#{http_opts[:Port]}" is in use. This should not have happened. Please start "middleman server" again.)
  end
end