Class: Middleman::PreviewServer::Checks::ServerNameResolvesToBindAddress

Inherits:
BasicCheck
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/preview_server/checks.rb

Overview

This checks if the server name resolves to the bind_address

If the users enters:

  1. server_name: www.example.com (10.0.0.1)
  2. bind_address: 127.0.0.01

This validation will fail

Instance Method Summary collapse

Constructor Details

#initializeServerNameResolvesToBindAddress

Returns a new instance of ServerNameResolvesToBindAddress.


27
28
29
# File 'middleman-core/lib/middleman-core/preview_server/checks.rb', line 27

def initialize
  @resolver = DnsResolver.new
end

Instance Method Details

#validate(information) ⇒ Object

Validate

Parameters:

  • information (Information)

    The information to be validated


35
36
37
38
39
40
41
42
43
44
# File 'middleman-core/lib/middleman-core/preview_server/checks.rb', line 35

def validate(information)
  return if resolver.ips_for(information.server_name).include? information.bind_address

  information.valid = false
  information.reason = format(
    'Server name "%<name>s" does not resolve to bind address "%<addr>s"',
    name: information.server_name,
    addr: information.bind_address
  )
end