Make preview host and port configurable in config.rb and also expose those variables to extensions which are curious. Closes #1477

This commit is contained in:
Thomas Reynolds 2015-03-01 18:17:22 -08:00
parent d60cd3a044
commit a71589becd
4 changed files with 18 additions and 6 deletions

View file

@ -1,3 +1,5 @@
with_layout false do
page "/spaces in file.html"
end
config[:port] = 5555

View file

@ -67,6 +67,14 @@ module Middleman
end
delegate :root_path, to: :"self.class"
# Which host preview should start on.
# @return [Fixnum]
config.define_setting :host, '0.0.0.0', 'The preview server host'
# Which port preview should start on.
# @return [Fixnum]
config.define_setting :port, 4567, 'The preview server port'
# Name of the source directory
# @return [String]
config.define_setting :source, 'source', 'Name of the source directory'

View file

@ -14,11 +14,9 @@ module Middleman::Cli
method_option :host,
type: :string,
aliases: '-h',
default: '0.0.0.0',
desc: 'Bind to HOST address'
method_option :port,
aliases: '-p',
default: '4567',
desc: 'The port Middleman will listen on'
method_option :verbose,
type: :boolean,

View file

@ -5,8 +5,6 @@ require 'middleman-core/logger'
# rubocop:disable GlobalVars
module Middleman
module PreviewServer
DEFAULT_PORT = 4567
class << self
attr_reader :app, :host, :port
delegate :logger, to: :app
@ -15,8 +13,6 @@ module Middleman
# @return [void]
def start(opts={})
@options = opts
@host = @options[:host] || '0.0.0.0'
@port = @options[:port] || DEFAULT_PORT
mount_instance(new_app)
logger.info "== The Middleman is standing watch at http://#{host}:#{port}"
@ -92,6 +88,7 @@ module Middleman
def new_app
opts = @options.dup
server = ::Middleman::Application.server
# Add in the meta pages application
@ -107,7 +104,14 @@ module Middleman
)
config[:environment] = opts[:environment].to_sym if opts[:environment]
config[:host] = opts[:host] if opts[:host]
config[:port] = opts[:port] if opts[:port]
end
@host = @app.config[:host]
@port = @app.config[:port]
@app
end
def start_file_watcher