Don't crash when running the preview server and not connected to any network (no public IP)

v3-stable
Ben Hollis 2015-05-03 18:48:31 -07:00
parent 08dee580aa
commit 9f5080edf9
1 changed files with 2 additions and 1 deletions

View File

@ -272,7 +272,8 @@ module Middleman
# An IPv4 address on this machine which should be externally addressable.
# @return [String]
def public_ip
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
ip = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }
ip ? ip.ip_address : '127.0.0.1'
end
end