Remove duplicate server methods and solve webrick logging in a platform-independent way
This commit is contained in:
parent
8c87bbc757
commit
64a2933161
|
@ -262,41 +262,4 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
|
||||||
# Create a new Class which is based on Middleman::Application
|
|
||||||
# Used to create a safe sandbox into which extensions and
|
|
||||||
# configuration can be included later without impacting
|
|
||||||
# other classes and instances.
|
|
||||||
#
|
|
||||||
# @return [Class]
|
|
||||||
def server(&block)
|
|
||||||
@@servercounter ||= 0
|
|
||||||
@@servercounter += 1
|
|
||||||
const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates a new Rack::Server
|
|
||||||
#
|
|
||||||
# @param [Hash] options to pass to Rack::Server.new
|
|
||||||
# @return [Rack::Server]
|
|
||||||
def start_server(options={})
|
|
||||||
opts = {
|
|
||||||
:Port => options[:port] || 4567,
|
|
||||||
:Host => options[:host] || "0.0.0.0",
|
|
||||||
:AccessLog => []
|
|
||||||
}
|
|
||||||
|
|
||||||
app_class = options[:app] ||= ::Middleman.server.inst
|
|
||||||
opts[:app] = app_class
|
|
||||||
|
|
||||||
require "webrick"
|
|
||||||
opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging]
|
|
||||||
opts[:server] = 'webrick'
|
|
||||||
|
|
||||||
server = ::Rack::Server.new(opts)
|
|
||||||
server.start
|
|
||||||
server
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -61,7 +61,7 @@ module Middleman::Cli
|
||||||
#
|
#
|
||||||
# @return [Middleman::Application]
|
# @return [Middleman::Application]
|
||||||
def shared_instance(verbose=false)
|
def shared_instance(verbose=false)
|
||||||
@_shared_instance ||= ::Middleman.server.inst do
|
@_shared_instance ||= ::Middleman::Application.server.inst do
|
||||||
set :environment, :build
|
set :environment, :build
|
||||||
set :logging, verbose
|
set :logging, verbose
|
||||||
end
|
end
|
||||||
|
|
|
@ -149,7 +149,7 @@ module Middleman
|
||||||
opts[:app] = app_class
|
opts[:app] = app_class
|
||||||
|
|
||||||
require "webrick"
|
require "webrick"
|
||||||
opts[:Logger] = WEBrick::Log::new(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null', 7) if !options[:logging]
|
opts[:Logger] = WEBrick::Log::new(nil, 0) if !options[:logging]
|
||||||
opts[:server] = 'webrick'
|
opts[:server] = 'webrick'
|
||||||
|
|
||||||
server = ::Rack::Server.new(opts)
|
server = ::Rack::Server.new(opts)
|
||||||
|
|
|
@ -47,7 +47,7 @@ Given /^the Server is running$/ do
|
||||||
set :show_exceptions, false
|
set :show_exceptions, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@server_inst = Middleman.server.inst do
|
@server_inst = Middleman::Application.server.inst do
|
||||||
initialize_commands.each do |p|
|
initialize_commands.each do |p|
|
||||||
instance_exec(&p)
|
instance_exec(&p)
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,7 +65,7 @@ module Middleman
|
||||||
env = (@options[:environment] || "development").to_sym
|
env = (@options[:environment] || "development").to_sym
|
||||||
is_logging = @options.has_key?(:debug) && @options[:debug]
|
is_logging = @options.has_key?(:debug) && @options[:debug]
|
||||||
|
|
||||||
app = ::Middleman.server.inst do
|
app = ::Middleman::Application.server.inst do
|
||||||
set :environment, env
|
set :environment, env
|
||||||
set :logging, is_logging
|
set :logging, is_logging
|
||||||
end
|
end
|
||||||
|
@ -76,7 +76,7 @@ module Middleman
|
||||||
opts[:app] = app_rack
|
opts[:app] = app_rack
|
||||||
opts[:logging] = is_logging
|
opts[:logging] = is_logging
|
||||||
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
||||||
::Middleman.start_server(opts)
|
::Middleman::Application.start_server(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop the forked Middleman
|
# Stop the forked Middleman
|
||||||
|
|
Loading…
Reference in a new issue