Class: Rails::Server

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

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.


76
77
78
79
# File 'lib/rails/commands/server.rb', line 76

def initialize(*)
  super
  set_environment
end

Instance Method Details

#appObject

TODO: this is no longer required but we keep it for the moment to support older config.ru files.


82
83
84
85
86
87
# File 'lib/rails/commands/server.rb', line 82

def app
  @app ||= begin
    app = super
    app.respond_to?(:to_app) ? app.to_app : app
  end
end

#default_optionsObject


115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rails/commands/server.rb', line 115

def default_options
  super.merge({
    Port:               ENV.fetch('PORT', 3000).to_i,
    DoNotReverseLookup: true,
    environment:        (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
    daemonize:          false,
    caching:            nil,
    pid:                Options::DEFAULT_PID_PATH,
    restart_cmd:        restart_command
  })
end

#middlewareObject


111
112
113
# File 'lib/rails/commands/server.rb', line 111

def middleware
  Hash.new([])
end

#opt_parserObject


89
90
91
# File 'lib/rails/commands/server.rb', line 89

def opt_parser
  Options.new
end

#set_environmentObject


93
94
95
# File 'lib/rails/commands/server.rb', line 93

def set_environment
  ENV["RAILS_ENV"] ||= options[:environment]
end

#startObject


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rails/commands/server.rb', line 97

def start
  print_boot_information
  trap(:INT) { exit }
  create_tmp_directories
  setup_dev_caching
  log_to_stdout if options[:log_stdout]

  super
ensure
  # The '-h' option calls exit before @options is set.
  # If we call 'options' with it unset, we get double help banners.
  puts 'Exiting' unless @options && options[:daemonize]
end