Skip to content

Commit

Permalink
Fix server environment [#3877 status:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
sniemela authored and josevalim committed Feb 10, 2010
1 parent f337ebc commit cafe882
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions railties/lib/rails/commands.rb
Expand Up @@ -33,10 +33,13 @@
require APP_PATH
Rails::Console.start(Rails::Application)
when 's', 'server'
require APP_PATH
require 'rails/commands/server'
# Initialize the server first, so environment options are set
server = Rails::Server.new
require APP_PATH

Dir.chdir(Rails::Application.root)
Rails::Server.start
server.start
when 'db', 'dbconsole'
require 'rails/commands/dbconsole'
require APP_PATH
Expand Down
15 changes: 11 additions & 4 deletions railties/lib/rails/commands/server.rb
Expand Up @@ -6,8 +6,8 @@ module Rails
class Server < ::Rack::Server
class Options
def parse!(args)
options = {}
args = args.dup
args, options = args.dup, {}

opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: rails server [options]"
opts.on("-p", "--port=port", Integer,
Expand All @@ -34,13 +34,20 @@ def parse!(args)
end
end

def initialize(*)
super
set_environment
end

def opt_parser
Options.new
end

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

def start
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
puts "=> Call with -d to detach" unless options[:daemonize]
Expand Down

0 comments on commit cafe882

Please sign in to comment.