Module: Middleman::CoreExtensions::Request::ServerMethods

Defined in:
middleman-core/lib/middleman-core/core_extensions/request.rb

Instance Method Summary (collapse)

Instance Method Details

- (Class) server(&block)

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.

Returns:

  • (Class)


131
132
133
134
135
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 131

def server(&block)
  @@servercounter ||= 0
  @@servercounter += 1
  const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application))
end

- (Rack::Server) start_server(options = {})

Creates a new Rack::Server

Parameters:

  • options (Hash) (defaults to: {})

    to pass to Rack::Server.new

Returns:

  • (Rack::Server)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 141

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(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null', 7) if !options[:logging]
  opts[:server] = 'webrick'

  server = ::Rack::Server.new(opts)
  server.start
  server
end