Skip to content

Commit

Permalink
Make preview host and port configurable in config.rb and also expose …
Browse files Browse the repository at this point in the history
…those variables to extensions which are curious. Closes middleman#1477
  • Loading branch information
tdreyno committed Mar 2, 2015
1 parent d60cd3a commit a71589b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions middleman-core/fixtures/large-build-app/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
with_layout false do
page "/spaces in file.html"
end

config[:port] = 5555
8 changes: 8 additions & 0 deletions middleman-core/lib/middleman-core/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def self.root_path
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'
Expand Down
2 changes: 0 additions & 2 deletions middleman-core/lib/middleman-core/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ class Server < Thor
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,
Expand Down
12 changes: 8 additions & 4 deletions middleman-core/lib/middleman-core/preview_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# rubocop:disable GlobalVars
module Middleman
module PreviewServer
DEFAULT_PORT = 4567

class << self
attr_reader :app, :host, :port
delegate :logger, to: :app
Expand All @@ -15,8 +13,6 @@ class << self
# @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}"
Expand Down Expand Up @@ -92,6 +88,7 @@ def shutdown

def new_app
opts = @options.dup

server = ::Middleman::Application.server

# Add in the meta pages application
Expand All @@ -107,7 +104,14 @@ def new_app
)

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
Expand Down

0 comments on commit a71589b

Please sign in to comment.