Skip to content

Commit

Permalink
Add Rack handler for 'rails server' integration
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Feb 3, 2016
1 parent 616ef45 commit b190c83
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,7 @@ Release 5.0.25
--------------

* Fixes a crash that occurs when using Nginx + HTTPS + Sub-requests. Closes GH-1724.
* Integrates into the `rails server` command. Please learn more at [the Passenger + Rails integration documentation](https://www.phusionpassenger.com/library/dev/ruby/rails_integration.html).
* [Standalone] Makes the `--address` option work more reliably if the passed hostname may resolve to multiple addresses. For example, if you pass `--address localhost` then previous versions could fail because Passenger thinks it's an IPv6 address (::1) while Nginx thinks it's an IPv6 address (127.0.0.1). Hostname resolution is now done in a consistent manner.
* [Standalone] Adds IPv6 support to the builtin engine.

Expand Down
2 changes: 1 addition & 1 deletion packaging/debian
2 changes: 1 addition & 1 deletion packaging/rpm
102 changes: 102 additions & 0 deletions src/ruby_supportlib/phusion_passenger/rack_handler.rb
@@ -0,0 +1,102 @@
# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2016 Phusion Holding B.V.
#
# "Passenger", "Phusion Passenger" and "Union Station" are registered
# trademarks of Phusion Holding B.V.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

## Magic comment: begin bootstrap ##
libdir = File.expand_path('..', File.dirname(__FILE__))
$LOAD_PATH.unshift(libdir)
begin
require 'rubygems'
rescue LoadError
end
require 'phusion_passenger'
## Magic comment: end bootstrap ##

PhusionPassenger.locate_directories

require 'rbconfig'

module Rack
module Handler
class PhusionPassenger
class << self
def run(app, options = {})
result = system(ruby_executable, '-S', find_passenger_standalone,
'start', *build_args(options))
if !result
raise "Error starting Passenger"
end
end

def environment
ENV['RAILS_ENV'] || 'development'
end

def to_s
'Passenger application server'
end

private
def build_args(options)
args = ['-e', environment]
if options[:Port]
args << '-p'
args << options[:Port].to_s
end
if options[:Host]
args << '-a'
args << options[:Host].to_s
end
if options[:config]
args << '-R'
args << options[:config].to_s
end
args
end

def rb_config
if defined?(::RbConfig)
::RbConfig::CONFIG
else
::Config::CONFIG
end
end

def ruby_executable
@ruby_executable ||= rb_config['bindir'] + '/' +
rb_config['RUBY_INSTALL_NAME'] + rb_config['EXEEXT']
end

def find_passenger_standalone
::File.join(::PhusionPassenger.bin_dir, 'passenger')
end
end
end

register 'passenger', 'Rack::Handler::PhusionPassenger'

def self.default(options = {})
Rack::Handler::PhusionPassenger
end
end
end

0 comments on commit b190c83

Please sign in to comment.