Upgraded Rails and RSpec
[monkeycharger.git] / vendor / rails / railties / lib / commands / servers / webrick.rb
blobb950376150e45e1f5b9d11267b84025323175723
1 require 'webrick'
2 require 'optparse'
3 require 'commands/servers/base'
5 OPTIONS = {
6   :port         => 3000,
7   :ip           => "0.0.0.0",
8   :environment  => (ENV['RAILS_ENV'] || "development").dup,
9   :server_root  => File.expand_path(RAILS_ROOT + "/public/"),
10   :server_type  => WEBrick::SimpleServer,
11   :charset      => "UTF-8",
12   :mime_types   => WEBrick::HTTPUtils::DefaultMimeTypes,
13   :debugger     => false
14   
17 ARGV.options do |opts|
18   script_name = File.basename($0)
19   opts.banner = "Usage: ruby #{script_name} [options]"
21   opts.separator ""
23   opts.on("-p", "--port=port", Integer,
24           "Runs Rails on the specified port.",
25           "Default: 3000") { |v| OPTIONS[:port] = v }
26   opts.on("-b", "--binding=ip", String,
27           "Binds Rails to the specified ip.",
28           "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
29   opts.on("-e", "--environment=name", String,
30           "Specifies the environment to run this server under (test/development/production).",
31           "Default: development") { |v| OPTIONS[:environment] = v }
32   opts.on("-m", "--mime-types=filename", String,
33                   "Specifies an Apache style mime.types configuration file to be used for mime types",
34                   "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
36   opts.on("-d", "--daemon",
37           "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
38           ) { OPTIONS[:server_type] = WEBrick::Daemon }
40   opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
42   opts.on("-c", "--charset=charset", String,
43           "Set default charset for output.",
44           "Default: UTF-8") { |v| OPTIONS[:charset] = v }
46   opts.separator ""
48   opts.on("-h", "--help",
49           "Show this help message.") { puts opts; exit }
51   opts.parse!
52 end
54 start_debugger if OPTIONS[:debugger]
56 ENV["RAILS_ENV"] = OPTIONS[:environment]
57 RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
59 require RAILS_ROOT + "/config/environment"
60 require 'webrick_server'
62 OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
64 puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
65 puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
66 DispatchServlet.dispatch(OPTIONS)