Class: Hanami::Commands::Server Private

Inherits:
Rack::Server
  • Object
show all
Defined in:
lib/hanami/commands/server.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Rack compatible server.

It is run with:

`bundle exec hanami server`

It runs the application, by using the server specified in your Gemfile (eg. Puma or Unicorn).

It enables code reloading by default. This feature is implemented via process fork and requires shotgun gem.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Server

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Server.

See Also:

Since:

  • 0.1.0



26
27
28
29
30
31
32
33
34
# File 'lib/hanami/commands/server.rb', line 26

def initialize(options)
  @_env    = Hanami::Environment.new(options)
  @options = _extract_options(@_env)

  if code_reloading?
    require 'shotgun'
    @app = Shotgun::Loader.new(@_env.rackup.to_s)
  end
end

Instance Attribute Details

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



20
21
22
# File 'lib/hanami/commands/server.rb', line 20

def options
  @options
end

Instance Method Details

#middlewareObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Primarily this removes the ::Rack::Chunked middleware which is the cause of Safari content-length bugs.

Since:

  • 0.1.0



40
41
42
43
44
45
# File 'lib/hanami/commands/server.rb', line 40

def middleware
  mw = Hash.new { |e, m| e[m] = [] }
  mw["deployment"].concat([::Rack::ContentLength, ::Rack::CommonLogger])
  mw["development"].concat(mw["deployment"] + [::Rack::ShowExceptions, ::Rack::Lint])
  mw
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Kickstart shotgun preloader if code reloading is supported

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
# File 'lib/hanami/commands/server.rb', line 50

def start
  if code_reloading?
    Shotgun.enable_copy_on_write
    Shotgun.preload
  end

  super
end