aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/server/server_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/commands/server/server_command.rb')
-rw-r--r--railties/lib/rails/commands/server/server_command.rb46
1 files changed, 39 insertions, 7 deletions
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index cf3903f3ae..703ec59087 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -1,7 +1,11 @@
+# frozen_string_literal: true
+
require "fileutils"
require "optparse"
require "action_dispatch"
require "rails"
+require "active_support/deprecation"
+require "active_support/core_ext/string/filters"
require "rails/dev_caching"
module Rails
@@ -18,10 +22,15 @@ module Rails
set_environment
end
- # TODO: this is no longer required but we keep it for the moment to support older config.ru files.
def app
@app ||= begin
app = super
+ if app.is_a?(Class)
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ Use `Rails::Application` subclass to start the server is deprecated and will be removed in Rails 6.0.
+ Please change `run #{app}` to `run Rails.application` in config.ru.
+ MSG
+ end
app.respond_to?(:to_app) ? app.to_app : app
end
end
@@ -64,9 +73,9 @@ module Rails
end
def print_boot_information
- url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
+ url = "on #{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" unless use_puma?
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
- puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
+ puts "=> Rails #{Rails.version} application starting in #{Rails.env} #{url}"
puts "=> Run `rails server -h` for more startup options"
end
@@ -91,6 +100,10 @@ module Rails
def restart_command
"bin/rails server #{ARGV.join(' ')}"
end
+
+ def use_puma?
+ server.to_s == "Rack::Handler::Puma"
+ end
end
module Command
@@ -113,6 +126,8 @@ module Rails
desc: "Specifies the PID file."
class_option "dev-caching", aliases: "-C", type: :boolean, default: nil,
desc: "Specifies whether to perform caching in development."
+ class_option "restart", type: :boolean, default: nil, hide: true
+ class_option "early_hints", type: :boolean, default: nil, desc: "Enables HTTP/2 early hints."
def initialize(args = [], local_options = {}, config = {})
@original_options = local_options
@@ -123,6 +138,7 @@ module Rails
def perform
set_application_directory!
+ prepare_restart
Rails::Server.new(server_options).tap do |server|
# Require application after server sets environment to propagate
# the --environment option.
@@ -146,7 +162,8 @@ module Rails
daemonize: options[:daemon],
pid: pid,
caching: options["dev-caching"],
- restart_cmd: restart_command
+ restart_cmd: restart_command,
+ early_hints: early_hints
}
end
end
@@ -155,9 +172,16 @@ module Rails
def user_supplied_options
@user_supplied_options ||= begin
# Convert incoming options array to a hash of flags
- # ["-p", "3001", "-c", "foo"] # => {"-p" => true, "-c" => true}
+ # ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true}
user_flag = {}
- @original_options.each_with_index { |command, i| user_flag[command] = true if i.even? }
+ @original_options.each do |command|
+ if command.to_s.start_with?("--")
+ option = command.split("=")[0]
+ user_flag[option] = true
+ elsif command =~ /\A(-.)/
+ user_flag[Regexp.last_match[0]] = true
+ end
+ end
# Collect all options that the user has explicitly defined so we can
# differentiate them from defaults
@@ -202,7 +226,11 @@ module Rails
end
def restart_command
- "bin/rails server #{@server} #{@original_options.join(" ")}"
+ "bin/rails server #{@server} #{@original_options.join(" ")} --restart"
+ end
+
+ def early_hints
+ options[:early_hints]
end
def pid
@@ -212,6 +240,10 @@ module Rails
def self.banner(*)
"rails server [puma, thin etc] [options]"
end
+
+ def prepare_restart
+ FileUtils.rm_f(options[:pid]) if options[:restart]
+ end
end
end
end