From f366325b3ba596989ce45f55d36bed8ac6409de3 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Mon, 17 Feb 2014 09:28:57 +0000 Subject: [PATCH 1/3] return localhost when host is 0.0.0.0 #1011 --- .../lib/middleman-core/preview_server.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 42730788..5ad4bb72 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -21,9 +21,8 @@ module Middleman @options = opts mount_instance(new_app) - scheme = https? ? 'https' : 'http' - logger.info "== The Middleman is standing watch at #{scheme}://#{host}:#{port}" - logger.info "== Inspect your site configuration at #{scheme}://#{host}:#{port}/__middleman/" + logger.info "== The Middleman is standing watch at #{uri}" + logger.info "== Inspect your site configuration at #{uri + '__middleman'}" @initialized ||= false return if @initialized @@ -264,6 +263,15 @@ module Middleman end end end + + # Returns the URI the preview server will run on + # @return [URI] + def uri + host = @host.eql?('0.0.0.0') ? 'localhost' : @host + scheme = https? ? 'https' : 'http' + URI("#{scheme}://#{host}:#{@port}") + end + end class FilteredWebrickLog < ::WEBrick::Log From cf58acda302c766b99c67cfc81fa18428fba13fb Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sun, 3 May 2015 15:01:00 -0700 Subject: [PATCH 2/3] Clean up commit f366325b3ba596989ce45f55d36bed8ac6409de3 a bit --- CHANGELOG.md | 1 + middleman-core/lib/middleman-core/preview_server.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d10c5e35..61f381d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ master === * The preview server can now serve over HTTPS using the `--https` flag. It will use an automatic self-signed cert which can be overridden using `--ssl_certificate` and `--ssl_private_key`. These settings can also be set in `config.rb` +* The preview server URL will use 'localhost' rather than '0.0.0.0'. 3.3.11 === diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 5ad4bb72..7a4c1282 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -267,7 +267,7 @@ module Middleman # Returns the URI the preview server will run on # @return [URI] def uri - host = @host.eql?('0.0.0.0') ? 'localhost' : @host + host = @host == '0.0.0.0' ? 'localhost' : @host scheme = https? ? 'https' : 'http' URI("#{scheme}://#{host}:#{@port}") end From 126888272c95f917bd24a5f587a0bf3d65636c7e Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sun, 3 May 2015 15:11:46 -0700 Subject: [PATCH 3/3] The preview server URL will once again use the machine's hostname if available. --- CHANGELOG.md | 1 + middleman-core/lib/middleman-core/application.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f381d9..8d7c408f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ master * The preview server can now serve over HTTPS using the `--https` flag. It will use an automatic self-signed cert which can be overridden using `--ssl_certificate` and `--ssl_private_key`. These settings can also be set in `config.rb` * The preview server URL will use 'localhost' rather than '0.0.0.0'. +* The preview server URL will once again use the machine's hostname if available. 3.3.11 === diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 3173b139..f508f171 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -1,3 +1,5 @@ +require 'socket' + # Using Tilt for templating require 'tilt' @@ -69,7 +71,7 @@ module Middleman # Which host preview should start on. # @return [Fixnum] - config.define_setting :host, '0.0.0.0', 'The preview server host' + config.define_setting :host, Socket.gethostname, 'The preview server host' # Which port preview should start on. # @return [Fixnum]