#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/server'

require 'webrick'
require 'webrick/https'

OPTIONS = {
  :port        => 3001,
  :ip        => "192.168.1.15",
  :environment    => (ENV['RAILS_ENV'] || "development").dup,
  :server_root    => File.expand_path(RAILS_ROOT + "/public/"),

}

ENV["RAILS_ENV"] = OPTIONS[:environment]
RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)

require RAILS_ROOT + "/config/environment"
require 'webrick_server'
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)

class SSLDispatchServlet < DispatchServlet
  def self.dispatch(options)
    Socket.do_not_reverse_lookup = true
    server = WEBrick::HTTPServer.new(:Port        => options[:port].to_i,
                     :ServerType    => options[:server_type],
                     :BindAddress    => options[:ip],
                     :SSLEnable        => true,
                     :SSLVerifyClient    => OpenSSL::SSL::VERIFY_NONE,
                     :SSLCertName    => [ [ "CN",
WEBrick::Utils::getservername ] ]
                    )
    server.mount('/', DispatchServlet, options)
    trap("INT") { server.shutdown }
    server.start
  end
end
puts "=> Rails application started on
http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
puts "=> Ctrl-c to shutdown"


SSLDispatchServlet.dispatch(OPTIONS)